본문 바로가기
Beakjoon&프로그래머스/Java

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

by 현장 2025. 2. 23.

-Code

class Solution {
    boolean solution(String s) {
        int[] cnt = new int[2];
        int idx;
        for (String el : s.toLowerCase().split("")) {
            if (el.equals("y")) cnt[0]++;
            else if (el.equals("p")) cnt[1]++;
        }

        return cnt[0] == cnt[1];
    }
}