Skip to content

Instantly share code, notes, and snippets.

@zhangxiaomu01
Created December 9, 2018 04:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
class Solution {
public:
int longestValidParentheses(string s) {
int len_s = s.size();
int counter = 0, maxLen = 0;
for(int i = 0; i < len_s; i++){
counter = 0;
for(int j = i; j < len_s; j++){
if(s[j] == '('){
counter ++;
}
else{
counter --;
}
if(counter < 0) break;
if(counter == 0){
maxLen = max(maxLen, j - i + 1);
}
}
}
return maxLen;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment