Scroll indicator done
728x90

https://school.programmers.co.kr/learn/courses/30/lessons/12916

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr


조건
  • 문자열 s의 길이 : 50 이하의 자연수
  • 문자열 s는 알파벳으로만 이루어져 있습니다.
public class Solution12916 {
    boolean solution(String s) {
        int pCnt = 0, yCnt = 0;  // p, y 카운트 변수
        s = s.toLowerCase();  // s 문자열 모두 소문자로 변환
        for(int i=0; i<s.length();i++){  // 문자열 길이만큼 반복하여 "p"일 때, "y"일 때 검사
            if(s.substring(i, i+1).equals("p")) pCnt++;
            else if(s.substring(i, i+1).equals("y")) yCnt++;
        }
        return pCnt == yCnt ? true : false;  // p의 개수와 y의 개수가 같으면 true, 아니면 false 반환
    }

    public static void main(String[] args) {
        Solution12916 solution12916 = new Solution12916();
        System.out.println(solution12916.solution("pPoooyYy"));
    }
}

 

728x90