Skip to content

Commit dfe88cf

Browse files
committed
longest-consecutive-sequence solution
1 parent 2a7b029 commit dfe88cf

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

longest-consecutive-sequence/JangAyeon.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ var longestConsecutive = function (nums) {
88
let numsSet = new Set(nums);
99
const N = nums.length;
1010

11-
for (let i = 0; i < N; i++) {
12-
let temp = nums[i];
13-
let length = 1;
14-
if (!numsSet.has(temp - 1)) {
11+
for (let num of numsSet) {
12+
if (!numsSet.has(num - 1)) {
13+
let temp = num;
14+
let length = 1;
15+
1516
while (numsSet.has(temp + 1)) {
1617
length += 1;
1718
temp += 1;

0 commit comments

Comments
 (0)