LTE,can somebody help me?!!


  • 1
    A
    public ArrayList<ArrayList<Integer>> threeSum(int[] nums) {
    	ArrayList<ArrayList<Integer>> arrayList = new ArrayList<>();
    	Arrays.sort(nums);
    	System.out.println(nums.toString());
    	for (int i = 0; i < nums.length && nums[i] <= 0; i++) {
    		int font = i + 1;
    		int tair = nums.length - 1;
    		if (i != 0 && nums[i] == nums[i - 1]) {
    			continue;
    		}
    		while (font < tair) {
    			if (nums[i] + nums[font] + nums[tair] == 0) {
    				ArrayList<Integer> tmp = new ArrayList<>();
    				tmp.add(nums[i]);
    				tmp.add(nums[font]);
    				tmp.add(nums[tair]);
    				arrayList.add(tmp);
    				while (font < tair && nums[font] == nums[font + 1]) {
    					font++;
    				}
    				while (font < tair && nums[tair] == nums[tair - 1]) {
    					tair--;
    				}
    				font++;
    				tair--;
    			} else if (nums[i] + nums[font] + nums[tair] < 0) {
    				font++;
    			} else {
    				tair--;
    			}
    
    		}
    	}
    	return arrayList;
    }

  • 0
    A

    when I changed the following declare state, it works.but anybody who can tell me why?

    ArrayList<Integer> tmp = new ArrayList<>();
    -->
    ArrayList<Integer> tmp = new ArrayList<Integer>();


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.