← 返回 walmartlabs 的题目列表3Sum (No Duplicate Triplets Assumed)
类型:online_judge
Problem: 3Sum (Assume No Duplicate Triplets Required)
Given an integer array nums, find all triplets (a, b, c) (from three distinct indices) such that:
a + b + c == 0
In this follow-up question, assume you do not need to deduplicate triplets (i.e., either inputs/requirements ensure no duplicates, or the interviewer accepts a non-deduplicated version).
Requirements
Explain your algorithm and time/space complexity (verbal explanation is sufficient).
If implementing: return the list of triplets in any order.
Scale (for complexity discussion)
1 <= n <= 10^4
-10^5 <= nums[i] <= 10^5
Example
Input
6
-1 0 1 2 -1 -4
Output
(口述题:可返回如 [-1,-1,2] 与 [-1,0,1];本追问默认不强制去重)