Skip to content

Commit

Permalink
a20
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzhengwei committed May 23, 2017
1 parent 6848f86 commit 1cf1d2c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ leetcode 题解

[19. Remove Nth Node From End of List](Solution/1-50/19.md)

[20. Valid Parentheses](Solution/1-50/20.md)

[21. Merge Two Sorted Lists](Solution/1-50/21.md)

[29. Divide Two Integers](Solution/1-50/29.md)
Expand Down
23 changes: 23 additions & 0 deletions Solution/1-50/20.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 20. Valid Parentheses
[题目链接](https://leetcode.com/problems/valid-parentheses/#/description)

```python
class Solution(object):
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
kv_dict = {'{': '}', '(': ')', '[': ']'}
data_list = []
for i in range(len(s)):
c = s[i]
if c in kv_dict.keys():
data_list.append(c)
elif c in kv_dict.values():
if len(data_list) == 0 or c != kv_dict[data_list.pop()]:
return False
if(len(data_list) > 0):
return False
return True
```

0 comments on commit 1cf1d2c

Please sign in to comment.