나의 풀이
public class Solution {
boolean solution(String s) {
int pcount1=0;
int ycount2=0;
for(int i=0; i<s.length(); i++) {
char c=s.charAt(i);
if(c=='P'||c=='p') pcount1++;
else if(c=='Y'||c=='y') ycount2++;
}
if(pcount1!=ycount2) {
return false;
}
return true;
}
}
다른 사람의 풀이
class Solution {
boolean solution(String s) {
s = s.toUpperCase();
return s.chars().filter( e -> 'P'== e).count() == s.chars().filter( e -> 'Y'== e).count();
}
}
▶ 일괄적으로 대문자로 동일한 다음에 갯수를 count하는 것이 point
'프로그래머스(자바) > LV.1(자바)' 카테고리의 다른 글
정수 내림차순으로 배치하기 (0) | 2022.12.12 |
---|---|
하샤드 수 = 숫자를 문자열로 전환 + 문자열을 숫자로 전환★ (0) | 2022.12.12 |
x만큼 간격이 있는 n개의 숫자 →a[i] =a[i-1] +x (0) | 2022.12.12 |
정수 제곱근 판별 (0) | 2022.12.12 |
자연수 뒤집어 배열로 만들기(자바) - 배열 요소를 끝부터 넣기 (0) | 2022.12.12 |