O24
3Sum - Zero Sum Triplets
Problem Statement & Objective
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. Notice that the solution set must not contain duplicate triplets.
Function Signature (Python)
three_sum(nums: list[int]) -> list[list[int]]Input & Output Contract
Output Rule:List of unique triplets summing to 0.
System Constraints
3 <= nums.length <= 3000
-10^5 <= nums[i] <= 10^5Example Execution Walkthrough
nums = [-1, 0, 1, 2, -1, -4]
result: [[-1, -1, 2], [-1, 0, 1]]Example Test Scenarios (3)
Example 1
Input:
[[-1,0,1,2,-1,-4]]Expected Output:
[[-1,-1,2],[-1,0,1]]Example 2: Çözüm Yok
Input:
[[0,1,1]]Expected Output:
[]Example 3: Üç Sıfır
Input:
[[0,0,0]]Expected Output:
[[0,0,0]]