Skip to content

Commit 200ea1e

Browse files
committed
[level 1] Title: 문자열 내 p와 y의 개수, Time: 0.04 ms, Memory: 74.1 MB -BaekjoonHub
1 parent 1c49c72 commit 200ea1e

2 files changed

Lines changed: 7 additions & 9 deletions

File tree

프로그래머스/1/12916. 문자열 내 p와 y의 개수/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
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

@@ -16,7 +16,7 @@
1616

1717
### 제출 일자
1818

19-
2026년 06월 22일 07:43:36
19+
2026년 06월 22일 07:45:04
2020

2121
### 문제 설명
2222

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
class 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
}

0 commit comments

Comments
 (0)