Skip to content

Commit 38f64f3

Browse files
committed
lognest-consecutive-sequence solution
1 parent b6dded4 commit 38f64f3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var longestConsecutive = function (nums) {
2+
const Set = new Set(nums);
3+
let maxLength = 0;
4+
5+
for (let num of Set) {
6+
if (!Set.has(num - 1)) {
7+
let currentNum = num;
8+
let count = 1;
9+
10+
// 연속된 숫자 탐색
11+
while (Set.has(currentNum + 1)) {
12+
currentNum++;
13+
count++;
14+
}
15+
16+
maxLen = Math.max(maxLength, count);
17+
}
18+
}
19+
20+
return maxLength;
21+
};

0 commit comments

Comments
 (0)