Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively. 题意：一个数组，由0,1,2组成，现在

Posted by 111qqz Thursday, April 13, 2017

Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution. 思路： 排序，然后two pointer,复杂度 O(n^2) /* *********************************************** Author :111qqz Created Time

Posted by 111qqz Thursday, April 13, 2017

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. 思路： O(n^2)枚举两个元素，变成2-

Posted by 111qqz Thursday, April 13, 2017

Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: The solution set must not contain duplicate triplets. 思路：排序O(nlgn)，然后枚举一个元素O(n

Posted by 111qqz Thursday, April 13, 2017