Created
June 18, 2014 22:50
-
-
Save Bekt/033c782054d5da47bbe7 to your computer and use it in GitHub Desktop.
Balanced Delimiters Problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Balanced Delimiters: https://www.hackerrank.com/contests/programming-interview-questions/challenges/balanced-delimiters""" | |
def isBalanced(delims): | |
stack = [] | |
matches = {')': '(', '}': '{', ']': '['} | |
for d in delims: | |
if d in ')]}': | |
if (not stack or stack.pop() != matches[d]): | |
return False | |
else: | |
stack.append(d) | |
return not stack | |
print(isBalanced(input())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment