class Solution { 
  public int[] twoSum(int[] nums, int target){
    int[] result = new int[2];
    int i = 0;
    int j = nums.length-1;
    boolean targetFound = false;
    while (i<nums.length-1 && j>=0){
      if((nums[i]+nums[j]) == target){
        targetFound = true;
        break;
      }
      if(!targetFound){
        if(j <= i=1){
          j = nums.length - 1;
          i++;
        }else{
          j--;
        }
      }
    }
    if(targetFound){
      result[0] = i;
      result[1] = j;
    }
    return result;
  }
}