[프로그래머스] 코딩테스트 연습 - 연습문제 Level 1 문자열 내 p와 y의 개수

uoahy·2021년 9월 27일
0

Solution.java

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

        int result = 0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == 'p' || c == 'P') result++;
            if (c == 'y' || c == 'Y') result--;
        }
        
        if (result != 0) answer = false;

        return answer;
    }
}

출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges

0개의 댓글