mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Update
This commit is contained in:
@ -170,39 +170,6 @@ public:
|
||||
|
||||
如果[两数之和](https://mp.weixin.qq.com/s/uVAtjOHSeqymV8FeQbliJQ)要求返回的是数值的话,就可以使用双指针法了。
|
||||
|
||||
> 更过算法干货文章持续更新,可以微信搜索「代码随想录」第一时间围观,关注后,回复「Java」「C++」 「python」「简历模板」「数据结构与算法」等等,就可以获得我多年整理的学习资料。
|
||||
|
||||
|
||||
|
||||
## tmp
|
||||
|
||||
```python
|
||||
class Solution:
|
||||
def threeSum(self, nums: List[int]) -> List[List[int]]:
|
||||
res = []
|
||||
nums.sort()
|
||||
for i in range(len(nums)):
|
||||
if nums[i] > 0 :
|
||||
return res
|
||||
if nums[i] == nums[i-1] and i>0:
|
||||
continue
|
||||
left = i + 1
|
||||
right = len(nums) - 1
|
||||
while left < right:
|
||||
if nums[i] + nums[left] + nums[right] > 0:
|
||||
right -= 1
|
||||
elif nums[i] + nums[left] + nums[right] < 0:
|
||||
left += 1
|
||||
else:
|
||||
res.append([nums[i], nums[left], nums[right]])
|
||||
while left < right and nums[right] == nums[right-1]:
|
||||
right -= 1
|
||||
while left < right and nums[left] == nums[left+1]:
|
||||
left += 1
|
||||
left += 1
|
||||
right -= 1
|
||||
return res
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user