Skip to content

Commit 0f0492a

Browse files
committed
Sync LeetCode submission Runtime - 323 ms (74.68%), Memory - 17.7 MB (63.13%)
1 parent f4cdf21 commit 0f0492a

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

0016-3sum-closest/solution.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
1-
# Approach 1 - Two Pointers
1+
# Approach 1: Two Pointers
22

3-
# Time: O(n^2)
3+
# Time: O(n ^ 2)
44

55
class Solution:
66
def threeSumClosest(self, nums: List[int], target: int) -> int:
77
diff = float('inf')
88
nums.sort()
9-
9+
1010
for i in range(len(nums)):
1111
lo, hi = i + 1, len(nums) - 1
12-
12+
1313
while lo < hi:
1414
total = nums[i] + nums[lo] + nums[hi]
1515
if abs(target - total) < abs(diff):
1616
diff = target - total
17-
1817
if total < target:
1918
lo += 1
2019
else:
2120
hi -= 1
22-
23-
if diff == 0:
24-
break
25-
21+
22+
if diff == 0:
23+
break
24+
2625
return target - diff
27-
28-

0 commit comments

Comments
 (0)