Update solution 0016

This commit is contained in:
halfrost
2021-07-26 21:21:21 +08:00
parent 07ddc128b4
commit ae5c145c3f
2 changed files with 6 additions and 0 deletions

View File

@ -11,6 +11,9 @@ func threeSumClosest(nums []int, target int) int {
if n > 2 {
sort.Ints(nums)
for i := 0; i < n-2; i++ {
if i > 0 && nums[i] == nums[i-1] {
continue
}
for j, k := i+1, n-1; j < k; {
sum := nums[i] + nums[j] + nums[k]
if abs(sum-target) < diff {