Skip to content

Commit 2e79901

Browse files
authored
Update 合法括号判定.md
1 parent 3d72935 commit 2e79901

File tree

1 file changed

+1
-27
lines changed

1 file changed

+1
-27
lines changed

高频面试系列/合法括号判定.md

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -85,32 +85,6 @@ char leftOf(char c) {
8585

8686
![labuladong](../pictures/labuladong.jpg)
8787

88-
[labuladong](https://github.com/labuladong) 提供 C++ 解法代码:
89-
90-
```cpp
91-
bool isValid(string str) {
92-
stack<char> left;
93-
for (char c : str) {
94-
if (c == '(' || c == '{' || c == '[')
95-
left.push(c);
96-
else // 字符 c 是右括号
97-
if (!left.empty() && leftOf(c) == left.top())
98-
left.pop();
99-
else
100-
// 和最近的左括号不匹配
101-
return false;
102-
}
103-
// 是否所有的左括号都被匹配了
104-
return left.empty();
105-
}
106-
107-
char leftOf(char c) {
108-
if (c == '}') return '{';
109-
if (c == ')') return '(';
110-
return '[';
111-
}
112-
```
113-
11488
[张三](any_link_you_want) 提供 Java 代码:
11589

11690
```java
@@ -135,4 +109,4 @@ def isValid(str):
135109

136110
[下一篇:如何寻找消失的元素](../高频面试系列/消失的元素.md)
137111

138-
[目录](../README.md#目录)
112+
[目录](../README.md#目录)

0 commit comments

Comments
 (0)