문자열 내 p와 y의 개수

sua·2022년 12월 16일
0

문제

풀이

class Solution {
    boolean solution(String s) {
        boolean answer = true;

        int p = 0;
        int y = 0;
        for(char c : s.toCharArray()) {
            if(c == 'p' || c == 'P') {
                p++;
            }
            if(c == 'y' || c == 'Y') {
                y++;
            }
        }
        
        if(p == y) {
            answer = true;
        } else {
            answer = false;
        }

        return answer;
    }
}

결과

profile
가보자고

0개의 댓글

관련 채용 정보