페이지 2 / 전체 2
2. 코드
package Test;
public class Pair {
public static void main(String[] args) {
String s = "((Hello))";
Pair pair = new Pair();
System.out.println(pair.check(s));
}
private boolean check(String s) {
boolean result = true;
int count = 0;
for (int inx = 0; inx < s.length(); inx++) {
char c = s.charAt(inx);
if (c == '(')
count++;
else if (c == ')')
count--;
if (count < 0) {
result = false;
break;
}
}
return result;
}
}
