maths.three_sum

https://en.wikipedia.org/wiki/3SUM

Functions

three_sum(→ list[list[int]])

Find all unique triplets in a sorted array of integers that sum up to zero.

Module Contents

maths.three_sum.three_sum(nums: list[int]) list[list[int]]

Find all unique triplets in a sorted array of integers that sum up to zero.

Args:

nums: A sorted list of integers.

Returns:

A list of lists containing unique triplets that sum up to zero.

>>> three_sum([-1, 0, 1, 2, -1, -4])
[[-1, -1, 2], [-1, 0, 1]]
>>> three_sum([1, 2, 3, 4])
[]