<aside> 📌 문제링크

</aside>

코딩테스트 연습 - 문자열 내 p와 y의 개수

<aside> 🗨️ 느낀점

</aside>

String.charAt()을 써도 됐는데, 불필요하게 toCharArray로 변환한거 같다.

<aside> 👨🏻‍🏫 내 코드

</aside>

boolean solution(String s) {

        int pCount = 0;
        int yCount = 0;
        int count = 0;

        for (char c : s.toCharArray()) {
            if (c == 'p' || c == 'P') {
                ++pCount;
            } else if (c == 'y' || c == 'Y') {
                ++yCount;
            } else {
                ++count;
            }
        }

        if (pCount == yCount) {
            return true;
        }

        if (count == s.length()) {
            return false;
        }

        return false;
    }

<aside> 🧐 참고코드

</aside>