(self, nums: List[int])
| 4 | |
| 5 | class Solution: |
| 6 | def threeSum(self, nums: List[int]) -> List[List[int]]: |
| 7 | nums.sort() |
| 8 | result = [] |
| 9 | |
| 10 | for i in range(len(nums) - 2): |
| 11 | if i > 0 and nums[i] == nums[i - 1]: |
| 12 | continue |
| 13 | |
| 14 | left = i + 1 |
| 15 | right = len(nums) - 1 |
| 16 | |
| 17 | while left < right: |
| 18 | total = nums[i] + nums[left] + nums[right] |
| 19 | |
| 20 | if total == 0: |
| 21 | result.append([nums[i], nums[left], nums[right]]) |
| 22 | while left < right and nums[left] == nums[left + 1]: |
| 23 | left += 1 |
| 24 | while left < right and nums[right] == nums[right - 1]: |
| 25 | right -= 1 |
| 26 | left += 1 |
| 27 | right -= 1 |
| 28 | elif total < 0: |
| 29 | left += 1 |
| 30 | else: |
| 31 | right -= 1 |
| 32 | |
| 33 | return result |
nothing calls this directly
no outgoing calls
no test coverage detected