Skip to content

Commit a1d8b97

Browse files
authored
Improved task 128
1 parent 7ffbbba commit a1d8b97

File tree

1 file changed

+2
-6
lines changed
  • src/main/js/g0101_0200/s0128_longest_consecutive_sequence

1 file changed

+2
-6
lines changed

Diff for: src/main/js/g0101_0200/s0128_longest_consecutive_sequence/solution.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ var longestConsecutive = function(nums) {
99
if (nums.length === 0) {
1010
return 0
1111
}
12-
13-
nums.sort((a, b) => a - b) // Sort the array in ascending order
12+
nums.sort((a, b) => a - b)
1413
let max = Number.MIN_SAFE_INTEGER
1514
let thsMax = 1
16-
1715
for (let i = 0; i < nums.length - 1; i++) {
1816
if (nums[i + 1] === nums[i] + 1) {
1917
thsMax += 1
@@ -22,11 +20,9 @@ var longestConsecutive = function(nums) {
2220
if (nums[i + 1] === nums[i]) {
2321
continue
2422
}
25-
// Start of a new sequence
2623
max = Math.max(max, thsMax)
27-
thsMax = 1
24+
thsMax = 1 // NOSONAR
2825
}
29-
3026
return Math.max(max, thsMax)
3127
};
3228

0 commit comments

Comments
 (0)