• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

fxss5201 / fxss-leetcode / 14559966275

20 Apr 2025 01:30PM CUT coverage: 96.345% (-0.04%) from 96.385%
14559966275

push

github

fxss5201
feat: 增加 14. 第一个元素、18. 获取元组长度、43. 实现 Exclude

1014 of 1091 branches covered (92.94%)

Branch coverage included in aggregate %.

0 of 2 new or added lines in 1 file covered. (0.0%)

3652 of 3752 relevant lines covered (97.33%)

6.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.22
/src/leetcode/threeSum/javascript.js
1
// 输入:nums = [-1,0,1,2,-1,-4]
1✔
2
// 输出:[[-1,-1,2],[-1,0,1]]
1✔
3

1✔
4
export function threeSum(nums) {
1✔
5
  nums = nums.sort((a, b) => a - b)
1✔
6
  const len = nums.length
1✔
7
  const res = []
1✔
8
  for (let i = 0; i < len - 2; i++) {
1✔
9
    if (i > 0 && nums[i] === nums[i - 1]) continue
4✔
10
    if (nums[i] + nums[len - 2] + nums[len - 1] < 0) continue
4✔
11
    if (nums[i] + nums[i + 1] + nums[i + 2] > 0) break
4✔
12
    let j = i + 1
1✔
13
    let k = len - 1
1✔
14
    while (j < k) {
4✔
15
      const sum = nums[i] + nums[j] + nums[k]
2✔
16
      if (sum > 0) {
2!
17
        k--
×
18
      } else if (sum < 0) {
2!
19
        j++
×
20
      } else {
2✔
21
        res.push([nums[i], nums[j], nums[k]])
2✔
22
        j++
2✔
23
        while (j < k && nums[j] === nums[j - 1]) {
2✔
24
          j++
×
25
        }
×
26
        k--
2✔
27
        while (j < k && nums[k] === nums[k + 1]) {
2✔
28
          k--
×
29
        }
×
30
      }
2✔
31
    }
2✔
32
  }
4✔
33
  return res
1✔
34
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc