首页 > 其他 > 详细

18. 4Sum

时间:2016-06-12 21:54:03      阅读:221      评论:0      收藏:0      [点我收藏+]

1. 问题描述

Given an array S of n integers, are there elements a, b, c, and d in S 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.

For example, given array S = [1, 0, -1, 0, -2, 2], and target = 0.

A solution set is:
[
    [-1, 0, 0, 1],
    [-2, -1, 1, 2],
    [-2, 0, 0, 2]
]

Tags:Array Hash Table Two Pointers

Similar Problems: (E) Two Sum (M) 3Sum

2. 解答思路
3. 代码


4. 反思

18. 4Sum

原文:http://www.cnblogs.com/whl2012/p/5578845.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!