java Two Sum


  • 0
    L

    public class Solution {
    public int[] twoSum(int[] nums, int target) {
    if (nums == null) return null;
    int[] result = new int[]{};
    for(int i=0,le=nums.length-1;i<le;i++){
    int size = i+1;
    while(size<=le){
    if(nums[i]+nums[size]==target){
    return result = new int[]{nums[i],nums[size]};
    }
    size ++;
    }
    }
    return result;
    }
    }


Log in to reply
 

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