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
.
Note: The solution set must not contain duplicate quadruplets.
Example 1:
1 |
|
Related Topics: Array
、Two Pointers
、Hash Table
解題邏輯與實作
Two Pointers
我這題一開始直接偷懶使用 3Sum 來回作答。
1 |
|
結果比我想像中好一點,我原本預期會超時,不過也沒好到哪裡去就是了只跑出了 804 / 47.58%。
上面這個勉強算是 Two Pointers ,但這題的 Tag 中還有一個 Hash Table 解法,先欠著吧,我好想睡 Orz