Skip to content

Commit e261b42

Browse files
committed
[Week1]
1 parent 6d42c0b commit e261b42

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
[백준#1522.문자열 교환.py]
3+
https://www.acmicpc.net/problem/1522
4+
5+
# 문자열 , 투 포인터
6+
7+
"""
8+
# 1. a의 개수 = sliding window 크기
9+
words= input()
10+
window_size = words.count("a")
11+
result = 999999999
12+
13+
# 원형 문자열
14+
words += words[0:window_size-1]
15+
# 슬라이싱 된 문자열 속 b의 개수 최소값
16+
for start in range(len(words) - (window_size-1)):
17+
result = min(result, words[start: start+ window_size].count("b"))
18+
19+
print(result)
Binary file not shown.

발제/W01/Test/1806_부분합.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'''
2+
[백준#1806.부분합]
3+
https://www.acmicpc.net/problem/1806
4+
5+
참조:
6+
https://aia1235.tistory.com/46
7+
'''
8+
9+
import sys
10+
N ,S = map(int, sys.stdin.readline().split())
11+
arr = list(map(int, input().split()))
12+
13+
start , end = 0, 0
14+
min_length = 100000
15+
partial_sum = arr[0]
16+
while start <= end :
17+
if partial_sum >= S : # S보다 큰 부분합인 경우
18+
min_length = min(min_length , end - start +1 ) # 최소 길이 업데이트 확인
19+
partial_sum -= arr[start] # start +1 이동
20+
start += 1
21+
else : #partial_sum < S :
22+
end += 1
23+
if end < N :
24+
partial_sum += arr[end]
25+
else : #반복문 끝
26+
break
27+
28+
29+
if min_length == 100000 : # 수열 끝 -> 조건 충족 x
30+
print(0)
31+
else :
32+
print(min_length)

0 commit comments

Comments
 (0)