Skip to content

Commit

Permalink
Created 128-Longest-Consecutive-Sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
loczek committed Jul 8, 2022
1 parent a223232 commit 55029d3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions typescript/128-Longest-Consecutive-Sequence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function longestConsecutive(nums: number[]): number {
const number = new Set(nums);
let longest = 0;

for (const n of nums) {
if (!number.has(n - 1)) {
let length = 0;
while (number.has(n + length)) {
length += 1;
}
longest = Math.max(length, longest);
}
}

return longest;
}

0 comments on commit 55029d3

Please sign in to comment.