GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing raw.githubusercontent.com — raw.githubusercontent.com

package LeetCode; import java.util.Arrays; import java.util.LinkedList; import java.util.List; public class KSum { public static List> fourSum(int[]nums,int target){ List> res=new LinkedList<>(); if (nums==null||nums.length==0){ return res; } Arrays.sort(nums); res=kSum(4,nums,0,target); return res; } public static List> kSum(int k,int[] nums,int startIndex,int target){ //保存结果 List> res=new LinkedList<>(); //不能够再进行增加了 if(k>nums.length-startIndex){ return res; } if(k==2){ int i=startIndex,j=nums.length-1; while(i temp=new LinkedList<>(); temp.add(nums[i]); temp.add(nums[j]); res.add(temp); while(istartIndex && nums[i]==nums[i-1]){ continue; } List>tempList=kSum(k-1,nums,i+1,target-nums[i]); for(List temp:tempList){ //每一次的添加nums[i] temp.add(0,nums[i]); //添加到最终的结果中去 res.add(temp); } } return res; } } public static void main(String[] args){ int[] nums={1,0,-1,0,-2,2}; int target=0; List> res=fourSum(nums,target); System.out.println(res); } }
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.