function solution(s){
let p=0;
let y=0;
let result = s.toUpperCase();
for(let i=0; i<s.length+1; i++){
if(result[i] ==="P"){
p++;
}
if(result[i] ==="Y"){
y++;
}
}
return p==y;
}
하지만 요 풀이가 좀더 맘에들었다.
function solution(s){
s.toUpperCase();
return s.toUpperCase().split("P").length === s.toUpperCase().split("Y").length;
}
'알고리즘' 카테고리의 다른 글
[프로그래머스] (1) | 2023.10.13 |
---|---|
[프로그래머스] 음양더하기 (0) | 2023.10.13 |
거스름돈 구하기 (0) | 2023.10.13 |
코드잇 문자열 뒤집기 (0) | 2023.10.13 |
[프로그래머스]문자열 정렬하기 (1) (0) | 2023.09.26 |