File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change
1
+ # Valid Parentheses
2
+
3
+ class Solution (object ):
4
+ def isValid (self , s ):
5
+
6
+ stack = []
7
+ mapping = {')' : '(' , '}' : '{' , ']' : '[' }
8
+
9
+ for char in s :
10
+ if char in mapping .values ():
11
+ stack .append (char )
12
+ elif char in mapping .keys ():
13
+ if not stack or mapping [char ] != stack .pop ():
14
+ return False
15
+ else :
16
+ continue
17
+
18
+ return not stack
19
+
20
+ solution = Solution ()
21
+ print (solution .isValid ("()" ))
Original file line number Diff line number Diff line change @@ -225,4 +225,5 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
225
225
- [ Find the Duplicate Number] ( Python/find_the_duplicate_number.py )
226
226
- [ Buy Two Chocolates] ( Python/buy_two_chocolates.py )
227
227
- [ First Missing Positive] ( Python/first_missing_positive.py )
228
- - [ Subarray Product Less Than K] ( Python/subarray_product_less_than_k.py )
228
+ - [ Subarray Product Less Than K] ( Python/subarray_product_less_than_k.py )
229
+ - [ Valid Parentheses] ( Python/valid_parentheses.py )
You can’t perform that action at this time.
0 commit comments