class Solution:
def threeSum(self, nums: List[int]) -> List[List[int]]:
rlt = []
nums.sort()
for i in range(len(nums)):
l = i + 1
r = len(nums)-1
while l < r:
if nums[i] + nums[l] + nums[r] == 0:
if [nums[i], nums[l], nums[r]] not in rlt:
rlt.append([nums[i], nums[l], nums[r]])
r -= 1
l += 1
elif nums[i] + nums[l] + nums[r] > 0:
r -= 1
else:
l += 1
return rlt
15,三数之和
最新推荐文章于 2022-03-22 21:43:14 发布