
내가 작성한 코드
class Solution {
boolean solution(String s) {
int pCount = 0;
int yCount = 0;
// 문자열 소문자로 변경한 뒤 배열화
for (char c : s.toLowerCase().toCharArray()) {
if(c == 'p') pCount++;
else if(c == 'y') yCount++;
}
return pCount == yCount;
}
}
다른 사람의 코드
class Solution {
boolean solution(String s) {
s = s.toUpperCase();
return s.chars().filter( e -> 'P'== e).count() == s.chars().filter( e -> 'Y'== e).count();
}
}
Share article