We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7ffbbba commit a1d8b97Copy full SHA for a1d8b97
src/main/js/g0101_0200/s0128_longest_consecutive_sequence/solution.js
@@ -9,11 +9,9 @@ var longestConsecutive = function(nums) {
9
if (nums.length === 0) {
10
return 0
11
}
12
-
13
- nums.sort((a, b) => a - b) // Sort the array in ascending order
+ nums.sort((a, b) => a - b)
14
let max = Number.MIN_SAFE_INTEGER
15
let thsMax = 1
16
17
for (let i = 0; i < nums.length - 1; i++) {
18
if (nums[i + 1] === nums[i] + 1) {
19
thsMax += 1
@@ -22,11 +20,9 @@ var longestConsecutive = function(nums) {
22
20
if (nums[i + 1] === nums[i]) {
23
21
continue
24
25
- // Start of a new sequence
26
max = Math.max(max, thsMax)
27
- thsMax = 1
+ thsMax = 1 // NOSONAR
28
29
30
return Math.max(max, thsMax)
31
};
32
0 commit comments