프로그래머스
프로그래머스 - 문자열 내 p와 y의 개수
thiago6
2019. 1. 8. 14:52
내 코드
class Solution {
boolean solution(String s) {
boolean answer = true;
int pCnt = 0;
int yCnt = 0;
char c;
for (int i = 0; i < s.length(); i ++) {
c = s.charAt(i);
if (c == 'p' || c == 'P') {
pCnt++;
} else if (c == 'y' || c == 'Y') {
yCnt++;
}
}
answer = pCnt == yCnt ? true : false;
return answer;
}
}
다른 방법 - s.toLowerCase();