You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`
func threeSumClosest(nums []int, target int) int {
if len(nums) == 3 {
return nums[0] + nums[1] + nums[2]
}
sort.Ints(nums)
sum := nums[0] + nums[1] + nums[2]
for i := 0; i < len(nums); i++ {
l := i+1
r := len(nums) - 1
for l < r {
current := nums[i] + nums[l] + nums[r]
if math.Abs(float64(sum - target)) > math.Abs(float64(target - current)) {
sum = current
}
if current < target {
l++
} else if current == target {
return target
} else {
r--
}
}
}
return sum
}
`
The text was updated successfully, but these errors were encountered:
`
func threeSumClosest(nums []int, target int) int {
if len(nums) == 3 {
return nums[0] + nums[1] + nums[2]
}
sort.Ints(nums)
sum := nums[0] + nums[1] + nums[2]
}
`
The text was updated successfully, but these errors were encountered: