We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8b438ec commit 77db6d1Copy full SHA for 77db6d1
learntosurf/2024-11-18-[BOJ]-#1522-문자열교환.py
@@ -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