标签:sel python als pre else span 内存 leetcode def
简单题:
用栈实现:
class Solution: def isValid(self, s: str) -> bool: if s==‘‘: return True if len(s)==1: return False stack=[] i=0 while i<len(s): if s[i] in ‘({[‘: stack.append(s[i]) i+=1 if i==len(s): return False else: if stack==[]: return False if (s[i]==‘)‘ and stack.pop()==‘(‘ )or (s[i]==‘}‘ and stack.pop()==‘{‘) or (s[i]==‘]‘ and stack.pop()==‘[‘): i+=1 else: return False if stack!=[]: return False return True
标签:sel python als pre else span 内存 leetcode def
原文地址:https://www.cnblogs.com/taoyuxin/p/11690893.html