# Leetcode 20. Valid Parentheses 有以下幾種'(', ')', '{', '}', '[', ']',判斷是否以正確順序關閉以及組合。 ## 想法 使用堆疊,判斷開關以及順序正確。 程式碼: ``` def isValid(self, s: str) -> bool: list = [] for i in s: if(i=="{"): list.append("}") elif(i=="["): list.append("]") elif(i=="("): list.append(")") else: if(len(list)==0): return False if(i!=list.pop()): return False if(len(list)!=0): return False return True ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up