문자열 내 p와 y의 개수

han.user();·2023년 4월 12일
0

프로그래머스

목록 보기
61/87
post-thumbnail

class Solution {
    boolean solution(String s) {
        
        s = s.toLowerCase();

        int countP = 0;
        int countY = 0;

        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == 'p') {
                countP++;
            } else if (c == 'y') {
                countY++;
            }
        }
        if (countP == countY) {
            return true;
        } else {
            return false;
        }
    }
}
profile
I'm still hungry.

0개의 댓글