public class Solution {

public int longestValidParentheses(String s) {

```
int size=s.length();
if(size==0||size==1) return size;
String va=null;
int i=0;
for(int j=1;j<size;){
if(s.charAt(i)=='('){
if(s.charAt(j)==')'){
va+="()";
i=j;
j++;
}else j++;
}else {
i++;
j++;
}
}
return va.length();
}
```

}