Skip to content

Commit 0278185

Browse files
authored
Merge pull request #4 from SaykoMe/sayko-solutions
Sayko solutions
2 parents c7a813f + 0bb981d commit 0278185

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Python/valid_parentheses.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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("()"))

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,5 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
225225
- [Find the Duplicate Number](Python/find_the_duplicate_number.py)
226226
- [Buy Two Chocolates](Python/buy_two_chocolates.py)
227227
- [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)

0 commit comments

Comments
 (0)