[JAVA 문제 풀이] 225. 문자열 내 p와 y의 개수

프로그래머스 (12916)
Stupefyee's avatar
Apr 25, 2025
[JAVA 문제 풀이] 225. 문자열 내 p와 y의 개수
notion image
 

내가 작성한 코드

class Solution { boolean solution(String s) { int pCount = 0; int yCount = 0; // 문자열 소문자로 변경한 뒤 배열화 for (char c : s.toLowerCase().toCharArray()) { if(c == 'p') pCount++; else if(c == 'y') yCount++; } return pCount == yCount; } }
 

다른 사람의 코드

class Solution { boolean solution(String s) { s = s.toUpperCase(); return s.chars().filter( e -> 'P'== e).count() == s.chars().filter( e -> 'Y'== e).count(); } }
 
Share article

stupefyee