Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b45eecc

Browse filesBrowse files
CTCI Challenge - 5 bracket validator
1 parent 2d3ef71 commit b45eecc
Copy full SHA for b45eecc

File tree

Expand file treeCollapse file tree

1 file changed

+28
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+28
-0
lines changed

‎CTCI/bracket-validator.py

Copy file name to clipboard
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
def Evaluate(str):
2+
stack = []
3+
set1, set2 = "<({[", ">)}]"
4+
for c in str :
5+
if c in set1:
6+
#print "c in pushChars, APPENDING: ", c
7+
stack.append(c)
8+
elif c in set2:
9+
#print "c in popChars: ", c
10+
if len(stack)==0:
11+
return False
12+
else:
13+
stackTop = stack.pop()
14+
#print "POPPING" , stackTop
15+
balancingBracket = set1[set2.index(c)]
16+
if stackTop != balancingBracket:
17+
#print "THIS NOW"
18+
return False
19+
#finally everything should be popped
20+
if len(stack)==0:
21+
return True
22+
else:
23+
return False
24+
25+
result = Evaluate("<html><head><body><h1>Still working on it</h1></body></head></html>")
26+
print "Bracket Validator: ", result
27+
result = Evaluate("<html><head><body><h1>Still working on it</h1</body></head></html>")
28+
print "Bracket Validator: ", result

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.