Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.

Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.

Input: nums = [2,7,11,15], target = 9
Output: [0,1]

Explanation:num[0]+num[1]=9

class FindTwoSum {
    public int[] twoSum(int[] nums, int target) {
   
        int c=0;
       for(int i=0;i<nums.length;i++)
       {
           for(int j=i+1;j<nums.length;j++)
           {
              c= nums[i]+nums[j];
               if(target==c)
               {
                   return new int[] {i,j};
               }
               
               
           }
           
           
       }
        
        return null;
        
    }
}

0 Comments

Leave a reply

* Your email/mobile address will not be published. required fields are marked.

* Email and mobile number will be verified before publishing the comments.

Name *
Email *
Mobile