Skip to content

Commit a379699

Browse files
committed
Merge branch 'master' of github.com:yanglbme/leetcode
2 parents b0d162a + 54db6fc commit a379699

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

solution/020.Valid Parentheses/Solution.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,26 @@ def isValid(self, s):
2121
pass
2222
else:
2323
f=False
24-
return f
24+
return f
25+
26+
class Solution():
27+
def isValid(self,s):
28+
"""
29+
:type s: str
30+
:rtype: bool
31+
"""
32+
left=['(','{','[']
33+
right={ ')':'(',
34+
']':'[',
35+
'}':'{' }
36+
stack=[]
37+
for i in s:
38+
if i in left:
39+
stack.append(i)
40+
elif stack and right[i] == stack.pop():
41+
continue
42+
else:
43+
return False
44+
if stack:
45+
return False
46+
return True
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def reverseString(self, s):
3+
"""
4+
:type s: str
5+
:rtype: str
6+
"""
7+
length=len(s)
8+
if length < 2:
9+
return s
10+
ns=''
11+
p=length-1
12+
while p >= 0:
13+
ns += s[p]
14+
p-=1
15+
return ns

0 commit comments

Comments
 (0)