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 b8d9436 commit 45241aaCopy full SHA for 45241aa
βlongest-consecutive-sequence/krokerdile.js
@@ -0,0 +1,28 @@
1
+/**
2
+ * @param {number[]} nums
3
+ * @return {number}
4
+ */
5
+var longestConsecutive = function(nums) {
6
+ if (nums.length === 0) return 0;
7
+
8
+ const numSet = new Set(nums);
9
+ let maxLength = 0;
10
11
+ for (let num of numSet) {
12
+ // μ°μ μμ΄μ μμμ μΈμ§ νμΈ
13
+ if (!numSet.has(num - 1)) {
14
+ let currentNum = num;
15
+ let currentLength = 1;
16
17
+ // μ°μλ μ«μ μλ λμ μ¦κ°
18
+ while (numSet.has(currentNum + 1)) {
19
+ currentNum += 1;
20
+ currentLength += 1;
21
+ }
22
23
+ maxLength = Math.max(maxLength, currentLength);
24
25
26
27
+ return maxLength;
28
+};
0 commit comments