자바/프로그래머스
[Programmers/JAVA] 올바른 괄호
2가
2022. 11. 29. 21:45
내 코드
class Solution {
boolean solution(String s) {
boolean answer = false;
int count=0;
for(int i=0; i<s.length(); i++) {
if(s.charAt(i)=='(') {
count++;
}else {
count--;
}
if(count<0) {
break;
}
}
if(count==0) {
answer=true;
}
return answer;
}
}
느낀점
시간초과때문에 두번을 갈아엎었는데도 안돼서...ㅜㅜ
결국 다른 사람들이 짜놓은 코드를 보고 풀었다...
난 바보다...