[Leetcode]20. Valid Parentheses
2024. 8. 1. 18:33ㆍAlgorithm
1. problem :
https://leetcode.com/problems/valid-parentheses/
2. solution 1 :
class Solution:
def isValid(self, s: str) -> bool:
hashMap = {')':'(',']':'[','}':'{'}
open_brackets = ['(','[','{']
temp_stack = []
for i in s:
if i in open_brackets:
temp_stack.append(i)
else:
if not temp_stack or hashMap[i] != temp_stack.pop():
return False
return not temp_stack
'Algorithm' 카테고리의 다른 글
[Leetcode]150. Evaluate Reverse Polish Notation (0) | 2024.08.01 |
---|---|
[Leetcode]155. Min Stack (0) | 2024.08.01 |
[Leetcode]42. Trapping Rain Water(x) (0) | 2024.08.01 |
[Leetcode]167. Two Sum II - Input Array Is Sorted (0) | 2024.07.31 |
[Leetcode]125. Valid Palindrome (0) | 2024.07.31 |