GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — githubTest/20_ValidParentheses.py at master · yychuyu/githubTest Expand file tree/ Copy path20_ValidParentheses.pyMore file actions 27 lines (26 loc) · 1010 Bytes / Copy path20_ValidParentheses.pyFile metadata and controls27 lines (26 loc) · 1010 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 class Solution: def isValid(self, s): """ :type s: str :rtype: bool """ if len(s) == 0: return True elif len(s) % 2 == 1 or s[0] == ")" or s[0] == "]" or s[0] == "}": return False else: d = {"(": ")", "[": "]", "{": "}"} tmp = s[0] for parenthese in s[1:]: tmp = tmp + parenthese # if parenthese != d[tmp[-1]] or parenthese != "(" or parenthese != "[" or parenthese != "{": # return False #len(tmp)>=2是为了防止诸如()[]的情况,{}消除后第一个tmp长度只有1,程序中断 if len(tmp) >= 2 and parenthese == d[tmp[-2]]: tmp = tmp[:-2] elif parenthese != "(" and parenthese != "[" and parenthese != "{": return False if len(tmp) == 0: return True else: return False |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |