Skip to content

Commit 77db6d1

Browse files
committed
[BOJ] #1522.문자열 교환 / 실버 1 / 50(O)
1 parent 8b438ec commit 77db6d1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
str = input()
2+
3+
# 'a'의 개수
4+
a_count = str.count('a')
5+
6+
# 'b'의 개수
7+
current_b = 0
8+
for i in range(a_count):
9+
if str[i] == 'b':
10+
current_b += 1
11+
12+
min_b = current_b
13+
14+
# 고정된 길이의 구간별 탐색
15+
for i in range(1, len(str)):
16+
# 이전 문자를 제거
17+
if str[i-1] == 'b':
18+
current_b -= 1
19+
# 새 문자를 추가
20+
if str[(i + a_count - 1) % len(str)] == 'b':
21+
current_b +=1
22+
min_b = min(min_b, current_b)
23+
24+
print(min_b)

0 commit comments

Comments
 (0)