We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 795a71d commit f86ca32Copy full SHA for f86ca32
1 file changed
live8/test88/문제1/박희경.py
@@ -0,0 +1,34 @@
1
+def solution(sequence, k):
2
+ answer = []
3
+
4
+ i, j = 0, 0
5
+ total = sum(sequence[i: j + 1])
6
+ while i + j < len(sequence) * 2 - 1:
7
+ if i <= j:
8
+ if total == k:
9
+ answer.append([i, j])
10
+ total -= sequence[i]
11
+ i += 1
12
+ j += 1
13
+ if j < len(sequence):
14
+ total += sequence[j]
15
+ elif total < k:
16
17
18
19
+ else:
20
21
22
23
+ # res = []
24
+ # if len(answer) == 1:
25
+ # return answer[0]
26
+ # min_diff = float("inf")
27
+ # for ans in answer:
28
+ # diff = ans[1] - ans[0]
29
+ # if diff < min_diff:
30
+ # res = ans
31
+ # min_diff = diff
32
+ # return res
33
+ answer = sorted(answer, key=lambda x: x[1] - x[0]) # 코드 개선
34
+ return answer[0]
0 commit comments