File tree 2 files changed +32
-2
lines changed
2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change 12
12
| 7 | [ Reverse Integer] ( https://leetcode.com/problems/reverse-integer/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/ReverseInteger.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/reverse_integer.py ) |
13
13
| 9 | [ PalindromeNumber] ( https://leetcode.com/problems/palindrome-number/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/PalindromeNumber.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/palindrome_number.py ) |
14
14
| 13 | [ Roman To Integer] ( https://leetcode.com/problems/roman-to-integer/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/RomanToInteger.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/roman_to_integer.py ) |
15
- | 14 | [ Longest Common Prefix] ( https://leetcode.com/problems/longest-common-prefix/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/LongestCommonPrefix.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/longest_common_prefix.py ) |
16
- | 20 | [ ValidParentheses] ( https://leetcode.com/problems/valid-parentheses/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/ValidParentheses.java ) |
15
+ | 14 | [ Longest Common Prefix] ( https://leetcode.com/problems/longest-common-prefix/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/LongestCommonPrefix.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/longest_common_prefix.py ) |
16
+ | 20 | [ ValidParentheses] ( https://leetcode.com/problems/valid-parentheses/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/ValidParentheses.java ) [ ![ Python ] ( https://img.icons8.com/color/35/000000/python.png )] ( python/valid_parentheses.py ) |
17
17
| 21 | [ Merge 2 Sorted Lists] ( https://leetcode.com/problems/merge-two-sorted-lists/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/Merge2SortedLists.java ) |
18
18
| 26 | [ Remove Duplicates From Sorted Array] ( https://leetcode.com/problems/remove-duplicates-from-sorted-array/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/RemoveDuplicatesFromSortedArray.java ) |
19
19
| 27 | [ Remove Element] ( https://leetcode.com/problems/remove-element/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/RemoveElement.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/remove_element.py ) |
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def __init__ (self ):
3
+ self .openBrackets = {
4
+ '(' , '{' , '['
5
+ }
6
+
7
+ self .inverse = {
8
+ ')' : '(' ,
9
+ '}' : '{' ,
10
+ ']' : '['
11
+ }
12
+
13
+ def isValid (self , string : str ) -> bool :
14
+ brackets = []
15
+ for character in string :
16
+ if self .isOpenBracket (character ):
17
+ brackets .append (character )
18
+ elif len (brackets ) != 0 and brackets [- 1 ] == self .inverse [character ]:
19
+ brackets .pop ()
20
+ else :
21
+ return False
22
+
23
+ return len (brackets ) == 0
24
+
25
+ def isOpenBracket (self , character : str ) -> bool :
26
+ return character in self .openBrackets
27
+
28
+
29
+ sol = Solution ()
30
+ print (sol .isValid ('()()(())({[]})' ))
You can’t perform that action at this time.
0 commit comments