class Solution {
boolean solution(String s) {
boolean answer = true;
char ch;
int cnt = 0;
for(int i = 0; i < s.length(); i++){
ch = s.charAt(i);
if(ch == 'p' || ch == 'P')
cnt ++;
else if(ch == 'y' || ch == 'Y')
cnt --;
if(cnt != 0){
answer = false;
}else{
answer = true;
}
}
return answer;
}
}
'Algorithm > 프로그래머스' 카테고리의 다른 글
[Lv. 1] 문자열을 정수로 바꾸기 (0) | 2023.04.27 |
---|---|
[Lv. 1] 자연수 뒤집어 배열로 만들기 (0) | 2023.04.24 |
[Lv. 1] x만큼 간격이 있는 n개의 숫자 (1) | 2023.04.21 |
[Lv. 1] 나머지가 1이 되는 수 찾기 (0) | 2023.04.21 |
[Lv. 1] 자릿수 더하기 (0) | 2023.04.20 |
댓글