Parentheses
check if valid, 須考慮 ')' 在開頭的情況, 遞歸時也要考慮 ’(‘ 個數大於 ’)' 個數
20. Valid Parentheses
def isValid(self, s: str) -> bool:
dic = {')':'(', ']':'[', '}':'{'}
stack = []
for c in s:
if c in dic:
left = '#' if not stack else stack.pop()
if left != dic[c]:
return False
else:
stack.append(c)
return not stack678. Valid Parenthesis String
22. Generate Parentheses
32. Longest Valid Parentheses
1190. Reverse Substrings Between Each Pair of Parentheses
921. Minimum Add to Make Parentheses Valid
1249. Minimum Remove to Make Valid Parentheses
301. Remove Invalid Parentheses
Last updated