Skip to content

Instantly share code, notes, and snippets.

@Bekt
Created June 18, 2014 22:50
Show Gist options
  • Save Bekt/033c782054d5da47bbe7 to your computer and use it in GitHub Desktop.
Save Bekt/033c782054d5da47bbe7 to your computer and use it in GitHub Desktop.
Balanced Delimiters Problem
"""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