Skip to content

Commit e67e4a2

Browse files
author
luzhipeng
committed
2 parents 68c8abf + 0cefb88 commit e67e4a2

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

problems/20.validParentheses.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ Output: true
7070
> 入: push 出 shift 就是队列
7171
## 代码
7272

73+
* 语言支持:JS,Python
7374

75+
Javascript Code:
7476
```js
7577
/*
7678
* @lc app=leetcode id=20 lang=javascript
@@ -163,6 +165,30 @@ var isValid = function(s) {
163165
return valid;
164166
};
165167
```
168+
Python Code:
169+
```
170+
class Solution:
171+
def isValid(self,s):
172+
stack = []
173+
map = {
174+
"{":"}",
175+
"[":"]",
176+
"(":")"
177+
}
178+
for x in s:
179+
if x in map:
180+
stack.append(map[x])
181+
else:
182+
if len(stack)!=0:
183+
top_element = stack.pop()
184+
if x != top_element:
185+
return False
186+
else:
187+
continue
188+
else:
189+
return False
190+
return len(stack) == 0
191+
```
166192

167193
## 扩展
168-
如果让你检查XML标签是否闭合如何检查, 更进一步如果要你实现一个简单的XML的解析器,应该怎么实现?
194+
如果让你检查XML标签是否闭合如何检查, 更进一步如果要你实现一个简单的XML的解析器,应该怎么实现?

problems/3.longestSubstringWithoutRepeatingCharacters.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 题目地址
2+
https://leetcode.com/problems/longest-substring-without-repeating-characters/description/
3+
14
## 题目描述
25
Given a string, find the length of the longest substring without repeating characters.
36

0 commit comments

Comments
 (0)