Skip to content

Commit edc9648

Browse files
committed
Python : 슬라이딩 윈도우 이론
1 parent 4a6b4ff commit edc9648

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# 슬라이딩 윈도우
2+
arr = [2, 4, 7, 10, 8, 4]
3+
window_size = 3
4+
5+
window_sum, max_sum, start = 0, 0, 0
6+
for end in range(len(arr)):
7+
window_sum += arr[end]
8+
if end >= (window_size - 1):
9+
max_sum = max(max_sum, window_sum)
10+
window_sum -= arr[start]
11+
start += 1
12+
print(max_sum)

0 commit comments

Comments
 (0)