您的位置:首页 > 其它

leetcode Longest Valid Parentheses

2015-05-01 00:21 316 查看
#include <vector>
class Solution {
public:
int longestValidParentheses(string s) {
int r = 0;
int r_max=0;
int pl= 0;
vector<int> app;
for(auto i=s.begin();i<s.end();i++){
if (*i=='(')  { pl++;app.push_back(r);r=0;}
else if (*i==')'){
if (pl>0) { pl--;r+=app.back()+2;app.pop_back();}
else r=0;
}
if (r>r_max) r_max=r;
}
return r_max;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  leetcode