class Solution:
def fourSum(self, nums, target):
nums.sort()
results = []
for i, num in enumerate(nums):
for j, num2 in enumerate(nums):
if i == j:
continue
else:
start = num + num2
left = 0
right = len(nums) - 1
while left < right:
if left == i or left == j:
left += 1
continue
if right == i or right == j:
right -= 1
continue
total = start + nums[right] + nums[left]
if total == target:
result = [num, num2, nums[right], nums[left]]
result.sort()
if result not in results:
results.append(result)
right -= 1
left += 1
elif total > target: # maker smaller
right -= 1
elif total < target: # make bigger
left += 1
return results
I feel like this makes sense to me (just one more loop over 3sum) but my result always gets scrambled up and this overall is O(N^3) which obviously isn't ideal
I realize i could go online and look at solutions-- but i'd rather keep working here iteratively until I get it fr