[HackerRank][Python3] Balanced Brackets
2018. 7. 20. 00:08 |
프로그래밍/HackerRank
Problem :
https://www.hackerrank.com/challenges/balanced-brackets/problem
My Solution :
#!/usr/bin/python3 def isBalanced(s): if len(s) % 2 != 0: return 'NO' pairs = { '(': ')', '{': '}', '[': ']', } stack = [] for bracket in s: if bracket in pairs: stack.append(bracket) else: if stack and pairs[stack.pop()] == bracket: continue else: return 'NO' if stack: return 'NO' return 'YES' t = int(input()) for _ in range(t): s = input() result = isBalanced(s) print(result)
'프로그래밍 > HackerRank' 카테고리의 다른 글
[HackerRank][Python3] Recursion: Davis' Staircase (0) | 2018.07.21 |
---|---|
[HackerRank][Python3] Recursion: Fibonacci Numbers (0) | 2018.07.20 |
[HackerRank][Python3] Tree: Huffman Decoding (0) | 2018.07.20 |
[HackerRank][Python3] Binary Search Tree : Lowest Common Ancestor (0) | 2018.07.20 |
[HackerRank][Python3] Queues: A Tale of Two Stacks (0) | 2018.07.19 |
[HackerRank][Python3] Abbreviation (0) | 2018.07.18 |
[HackerRank][Python3] Max Array Sum (0) | 2018.07.18 |
[HackerRank][Python3] Making Candies (0) | 2018.07.18 |
최근에 달린 댓글 최근에 달린 댓글