Skip to content

5 2 月, 2021

LeetCode: 18-4Sum 解題紀錄

Last Updated on 2022-07-20 by Clay


題目

Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.

Notice that the solution set must not contain duplicate quadruplets.

Example:

Input: nums = [1,0,-1,0,-2,2], target = 0
Output: [[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]

這個題目是 2Sum3Sum 的衍伸版,同樣給定一個整數陣列輸入,我們要找出由四個數加總為 0 的所有組合。

Read More »LeetCode: 18-4Sum 解題紀錄