괄호가 바르게 짝지어졌다는 것은 '(' 문자로 열렸으면 반드시 짝지어서 ')' 문자로 닫혀야 한다는 뜻이다.
예를 들어 "()()" 또는 "(())()"는 올바른 괄호이다.
")()(" 또는 "(()("는 올바르지 않은 괄호이다.
"(" 또는 ")" 로만 이루어진 문자열 string이 주어졌을 때, 문자열 string이 올바른 괄호이면 true를 return하고, 올바르지 않은 괄호이면 false를 return 하는 solution 함수를 완성하라.

public class Solution {
boolean solution(String string) {
boolean answer = true;
String[] parentheses = string.split("");
int openCount = 0;
int closeCount = 0;
for (int i = 0; i < parentheses.length; i += 1) {
if (parentheses[0].equals(")")) {
return false;
}
if (parentheses[i].equals("(")) {
openCount += 1;
}
if (parentheses[i].equals(")")) {
closeCount += 1;
}
}
if (openCount == closeCount) {
answer = true;
}
if (openCount != closeCount) {
answer = false;
}
return answer;
}
}

public class Solution {
boolean solution(String string) {
boolean answer = false;
String[] parentheses = string.split("");
int count = 0;
for (int i = 0; i < parentheses.length; i += 1) {
if (parentheses[0].equals(")")) {
return false;
}
if (parentheses[i].equals("(")) {
count += 1;
}
if (parentheses[i].equals(")")) {
count -= 1;
}
if (count < 0) {
break;
}
}
if (count == 0) {
answer = true;
}
return answer;
}
}

public class Solution {
boolean solution(String string) {
boolean answer = false;
int count = 0;
for (int i = 0; i < string.length(); i += 1) {
if (string.charAt(0)==')') {
return false;
}
if (string.charAt(i)=='(') {
count += 1;
}
if (string.charAt(i)==')') {
count -= 1;
}
if (count < 0) {
break;
}
}
if (count == 0) {
answer = true;
}
return answer;
}
}