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]longest Valid Parentheses(!!)
- leetcode:Longest Valid Parentheses
- [leetcode-32]Longest Valid Parentheses(java)
- [LeetCode] 最长合法括号 longest valid parentheses
- LeetCode Longest Valid Parentheses
- 【leetcode】Longest Valid Parentheses
- [LeetCode] Longest Valid Parentheses
- leetcode32---Longest Valid Parentheses
- [LeetCode]Longest Valid Parentheses
- LeetCode OJ Longest Valid Parentheses
- Java for LeetCode 032 Longest Valid Parentheses
- [LeetCode] Longest Valid Parentheses
- longest valid parentheses--LeetCode
- [LeetCode] Longest Valid Parentheses
- [leetcode] Longest Valid Parentheses
- LeetCode Longest Valid Parentheses
- [LeetCode] Longest Valid Parentheses
- LeetCode: Longest Common Prefix, Valid Parentheses
- Leetcode: Longest Valid Parentheses
- (Java)LeetCode-32. Longest Valid Parentheses