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 2a7b029 commit dfe88cfCopy full SHA for dfe88cf
longest-consecutive-sequence/JangAyeon.js
@@ -8,10 +8,11 @@ var longestConsecutive = function (nums) {
8
let numsSet = new Set(nums);
9
const N = nums.length;
10
11
- for (let i = 0; i < N; i++) {
12
- let temp = nums[i];
13
- let length = 1;
14
- if (!numsSet.has(temp - 1)) {
+ for (let num of numsSet) {
+ if (!numsSet.has(num - 1)) {
+ let temp = num;
+ let length = 1;
15
+
16
while (numsSet.has(temp + 1)) {
17
length += 1;
18
temp += 1;
0 commit comments