Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
441 B
0
Indexable
Never
class Solution {
    public int[] twoSum(int[] nums, int target) {
        int[] ans=new int[2];
        Arrays.sort(nums);
        while(i<j){
            if(nums[i]+nums[j]==target){
                ans[0]=nums[i];
                ans[j]=nums[j];
                return ans;
                
            }
            else if(nums[i]+nums[j]<target)
                i++;
            else
                j++;
            
        }
    }
}