We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b6dded4 commit 38f64f3Copy full SHA for 38f64f3
longest-consecutive-sequence/moonjonghoo.js
@@ -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