Update 32. Longest Valid Parentheses.md

This commit is contained in:
ShusenTang 2020-06-18 09:22:15 +08:00 committed by GitHub
parent 7ae5369958
commit 4d94af8461
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}
};
```
```