last commit, giving up, wip
This commit is contained in:
parent
07b46554a3
commit
aa5073c881
@ -33,21 +33,38 @@ def solution(nums: list[int]) -> list[list[int]]:
|
||||
if sum(nums) == 0: return [nums]
|
||||
else: return []
|
||||
|
||||
r = []
|
||||
s = []
|
||||
for p0 in range(len(nums)):
|
||||
for p1 in range(p0 + 1, len(nums)):
|
||||
inverse = -1 * (nums[p0] + nums[p1])
|
||||
if inverse in set(nums[p1+1:]) and set({nums[p0], nums[p1], inverse}) not in s:
|
||||
r.append([nums[p0], nums[p1], inverse])
|
||||
s.append({nums[p0], nums[p1], inverse})
|
||||
|
||||
return list(map(lambda ss: list(ss), r))
|
||||
nums.sort()
|
||||
triplets: list[list[int]] = []
|
||||
|
||||
for p in range(len(nums)):
|
||||
if p == len(nums) - 3:
|
||||
if nums[-1] + nums[-2] + nums[-3] == 0:
|
||||
triplets.append([nums[-1], nums[-2], nums[-3]])
|
||||
break
|
||||
pl = p + 1
|
||||
pr = len(nums) - 1
|
||||
while pl != pr:
|
||||
print(p, pl, pr)
|
||||
s = nums[p] + nums[pl] + nums[pr]
|
||||
if s < 0:
|
||||
pl += 1
|
||||
elif s > 0:
|
||||
pr -= 1
|
||||
else:
|
||||
triplets.append([nums[p], nums[pl], nums[pr]])
|
||||
break
|
||||
|
||||
p = 1
|
||||
while p < len(triplets):
|
||||
if sorted(triplets[p]) == sorted(triplets[p - 1]):
|
||||
triplets.pop(p)
|
||||
else: p += 1
|
||||
return triplets
|
||||
|
||||
print(solution([1,-1,-1,0]), solution([1,-1,-1,0]) == [[-1, 0, 1]])
|
||||
print(solution([0,0]) == [])
|
||||
print(solution([-1,0,1,2,-1,-4]), solution([-1,0,1,2,-1,-4]) == [[-1,-1,2],[-1,0,1]])
|
||||
print(solution([0,1,1]) == [])
|
||||
print(solution([0,0,0]) == [[0,0,0]])
|
||||
print(solution([0,0,0,0]) == [[0,0,0]])
|
||||
|
||||
print(solution([0,0,0,0]) == [[0,0,0]], solution([0,0,0,0]))
|
||||
print(solution([0,0,0,0,0]))
|
||||
|
Loading…
x
Reference in New Issue
Block a user