public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(validParenthese("((())(())"));
System.out.println(validParenthese("((())(()))"));
}
static boolean validParenthese(String s) {
int count = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == '(') {
count++;
} else if (s.charAt(i) == ')') {
count--;
if (count < 0) {
return false;
}
}
}
return count == 0;
}
valid Parenthese
最新推荐文章于 2018-12-06 21:58:53 发布