MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / twoSum

Method twoSum

TwoSumIISortedArray.java:2–16  ·  view source on GitHub ↗
(int[] numbers, int target)

Source from the content-addressed store, hash-verified

1class Solution {
2 public int[] twoSum(int[] numbers, int target) {
3 int start=0;
4 int end=numbers.length-1;
5 while(start<end)
6 {
7 int sum = numbers[start] + numbers[end];
8 if(sum==target)
9 {
10 return new int[]{start+1,end+1};
11 }
12 if(sum<target) start++;
13 else end--;
14 }
15 return null;
16 }
17}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected