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 e902aaa commit b86951eCopy full SHA for b86951e
longest-consecutive-sequence/sooooo-an.ts
@@ -0,0 +1,24 @@
1
+function longestConsecutive(nums: number[]): number {
2
+ if (!nums.length) return 0;
3
+
4
+ nums.sort((a, b) => a - b);
5
+ let longest = 1;
6
+ let currentStreak = 1;
7
8
+ for (let i = 1; i < nums.length; i++) {
9
+ if (nums[i] === nums[i - 1]) continue;
10
+ if (nums[i] === nums[i - 1] + 1) {
11
+ currentStreak++;
12
+ } else {
13
+ longest = Math.max(longest, currentStreak);
14
+ currentStreak = 1;
15
+ }
16
17
18
+ return Math.max(longest, currentStreak);
19
+}
20
21
+/**
22
+ * * Runtime: 37ms / 74.15%
23
+ * * Memory: 67.88MB / 93.54%
24
+ */
0 commit comments