본문 바로가기

Coding Test/프로그래머스

[프로그래머스/자바] 문자열 내 p와 y의 개수

class Solution {
    boolean solution(String s) {
        s = s.toLowerCase();
        char[] list = s.toCharArray();
        int p = 0;
        int y = 0;
        
        for(char c : list) {
            if (c == 'p') p++;
            else if (c == 'y') y++;
        }
        
        return p == y;
    }
}