Skip to content

Instantly share code, notes, and snippets.

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