Return indices of the two numbers such that they add up to target

Return indices of the two numbers such that they add up to target




Java Solution:-

public class Main

{

public static void main(String[] args) {

    

    int n[]={1,2,0};

    int target=2;

System.out.println(twosum(n,target));

}

public static int twosum(int n[], int target){

    int i=0,j=0,p=0;

    int q=0;

    

    j=n.length-1;

  //   System.out.println(j);

    while(j>=0){

      

        q=n[j];

        System.out.println(j);

        for(i=0;i<n.length;i++){

            if(n[i]+q==target){

               break;

            }

        }

          j--;

    }

// System.out.println(i+" "+j);

   return 0;

}

}


Post a Comment

0 Comments