测试一下- public static void main(String[] args) {
- String src = "((()))()((()))";
- System.out.println(match(src));
- }
- private static boolean match(String src) {
- int start = 0;
- for(int i = 0 ;i < src.length();i++){
- switch (src.charAt(i)) {
- case '(':
- start++;
- break;
- case ')':
- start--;
- if(start<0){
- return false;
- }
- }
- }
- return true;
- }
复制代码 |