Skip to content

Commit e0d6df5

Browse files
committed
[BOJ] #1522. 문자열 교환 / 실버1 / 30분 / 힌트, 성공
1 parent 7a3e2c3 commit e0d6df5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
# 1. 문자열 입력받기
5+
ab_str = input().rstrip()
6+
7+
# 2. a의 개수 계산
8+
a = ab_str.count('a')
9+
10+
# 3. 원형 문자열 처리
11+
ab_str += ab_str # 문자열을 두 배로 늘림
12+
13+
# 4. 슬라이딩 윈도우로 최소 b의 개수 계산
14+
answer = len(ab_str) # 충분히 큰 초기값 설정
15+
for i in range(len(ab_str) // 2):
16+
answer = min(answer, ab_str[i:i+a].count('b')) # b의 개수 최소값 갱신
17+
18+
# 5. 결과 출력
19+
print(answer)

0 commit comments

Comments
 (0)