public int[] twoSum(int[] nums, int target) { int len = nums.length; if(len==1) if(target == nums[0]) return nums; else return new int[0]; int i = 0,j = len-1; while (i<j){ int x = nums[i] + nums[j]; if(x>target) j--; else if(x<target) i++; else return new int[]{nums[i],nums[j]}; } return new int[0]; }