mirror of
https://github.com/ShusenTang/LeetCode.git
synced 2024-09-02 14:20:01 +00:00
Update 32. Longest Valid Parentheses.md
This commit is contained in:
parent
7ae5369958
commit
4d94af8461
@ -12,7 +12,9 @@
|
||||
* 如果遇到左括号或者栈空,则将当前下标i压入栈;
|
||||
* 如果遇到右括号且栈顶为左括号,则遇到了匹配的括号对,将栈顶弹出即可;
|
||||
|
||||
然后就可以计算以字符`s[i]`作为结尾的最大长度:`i - stk.top()`。
|
||||
然后就可以计算以字符`s[i]`作为结尾的最大长度:
|
||||
* 若栈不空,则长度为`i - stk.top()`;
|
||||
* 否则,即栈空,说明前面的都能匹配,则长度为`i+1`。
|
||||
|
||||
时空复杂度均为O(n)
|
||||
|
||||
@ -107,4 +109,4 @@ public:
|
||||
return res;
|
||||
}
|
||||
};
|
||||
```
|
||||
```
|
||||
|
||||
Loading…
Reference in New Issue
Block a user