标签:
题目描述:public class Solution {
public int LongestValidParentheses(string s) {
int max = 0;
var stack = new Stack<int>();
for (int i = 0; i < s.Length; i++) {
if (s[i] == ‘)‘ && stack.Count > 0 && s[stack.Peek()] == ‘(‘) {
stack.Pop();
if (stack.Count == 0){
max = i + 1;
}
else{
max = Math.Max(max, i - stack.Peek());
}
} else {
stack.Push(i);
}
}
return max;
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
LeetCode -- Longest Valid Parentheses
标签:
原文地址:http://blog.csdn.net/lan_liang/article/details/48731261