File tree Expand file tree Collapse file tree
프로그래머스/1/12916. 문자열 내 p와 y의 개수 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# [ level 1] 문자열 내 p와 y의 개수 - 12916
22
3- [ 문제 링크] ( https://school.programmers.co.kr/learn/courses/30/lessons/12916?language=java )
3+ [ 문제 링크] ( https://school.programmers.co.kr/learn/courses/30/lessons/12916 )
44
55### 성능 요약
66
7- 메모리: 73.8 MB, 시간: 0.04 ms
7+ 메모리: 74.1 MB, 시간: 0.04 ms
88
99### 구분
1010
1616
1717### 제출 일자
1818
19- 2026년 06월 22일 07:43:36
19+ 2026년 06월 22일 07:45:04
2020
2121### 문제 설명
2222
Original file line number Diff line number Diff line change 11class Solution {
22 boolean solution (String s ) {
33 s = s .toUpperCase ();
4- int P_cnt = 0 ;
5- int Y_cnt = 0 ;
4+ int cnt = 0 ;
65 for (int i = 0 ; i < s .length (); i ++) {
7- if (s .charAt (i ) == 'P' ) P_cnt += 1 ;
8- else if (s .charAt (i ) == 'Y' ) Y_cnt += 1 ;
6+ if (s .charAt (i ) == 'P' ) cnt ++ ;
7+ else if (s .charAt (i ) == 'Y' ) cnt -- ;
98 }
10- if (P_cnt == Y_cnt ) return true ;
11- else return false ;
9+ return cnt == 0 ;
1210 }
1311}
You can’t perform that action at this time.
0 commit comments