File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -21,4 +21,26 @@ def isValid(self, s):
21
21
pass
22
22
else :
23
23
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
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments