未验证 提交 2e799019 编写于 作者: L labuladong 提交者: GitHub

Update 合法括号判定.md

上级 3d72935d
......@@ -85,32 +85,6 @@ char leftOf(char c) {
![labuladong](../pictures/labuladong.jpg)
[labuladong](https://github.com/labuladong) 提供 C++ 解法代码:
```cpp
bool isValid(string str) {
stack<char> left;
for (char c : str) {
if (c == '(' || c == '{' || c == '[')
left.push(c);
else // 字符 c 是右括号
if (!left.empty() && leftOf(c) == left.top())
left.pop();
else
// 和最近的左括号不匹配
return false;
}
// 是否所有的左括号都被匹配了
return left.empty();
}
char leftOf(char c) {
if (c == '}') return '{';
if (c == ')') return '(';
return '[';
}
```
[张三](any_link_you_want) 提供 Java 代码:
```java
......@@ -135,4 +109,4 @@ def isValid(str):
[下一篇:如何寻找消失的元素](../高频面试系列/消失的元素.md)
[目录](../README.md#目录)
\ No newline at end of file
[目录](../README.md#目录)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册