Skip to content

Commit fc84bbf

Browse files
author
Eric
committed
88차 1번 문제풀이
1 parent 6a329a9 commit fc84bbf

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

live8/test88/문제1/황장현.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function solution(sequence, k) {
2+
let start = 0;
3+
let end = 0;
4+
let sum = sequence[0];
5+
let minLength = Infinity;
6+
let answer = [];
7+
8+
while (end < sequence.length) {
9+
if (sum === k) {
10+
if (end - start < minLength) {
11+
minLength = end - start;
12+
answer = [start, end];
13+
}
14+
sum -= sequence[start++];
15+
} else if (sum < k) {
16+
end++;
17+
if (end < sequence.length) sum += sequence[end];
18+
} else {
19+
sum -= sequence[start++];
20+
}
21+
}
22+
23+
return answer;
24+
}
25+
26+
console.log(solution([1, 1, 1, 2, 3, 4, 5], 5));

0 commit comments

Comments
 (0)