这题的leetcode测试用例错了吧
public class Solution {
int max = 0;
public int longestValidParentheses(String s) {
getResult(s, "", 0, 0);
return max*2;
}
private void getResult (String left, String result, int leftCount, int maxCount) {
if (left.length() == 0) {
if (result.length() != 0 && leftCount == 0) {
if (max < maxCount) {
max = maxCount;
}
}
return;
}
if (left.charAt(0) == '(') {
getResult(left.substring(1), result + "(", leftCount + 1, maxCount + 1);
getResult(left.substring(1), result, leftCount, maxCount);
} else {
if (leftCount > 0) {
getResult(left.substring(1), result + ")", leftCount - 1, maxCount);
}
getResult(left.substring(1), result, leftCount, maxCount);
}
}
}