sum of two numbers

Given an array of integers and a target value, find two numbers in the array that sum to the target value.

You can assume that each input corresponds to only one answer, and that the same elements cannot be reused.

 1 class Solution {
 2     public int[] twoSum(int[] nums, int target) {
 3         for(int i=0; i<nums.length;i++){
 4             for(int j = i+1 ; j<nums.length;j++){
 5                 if((nums[i]+nums[j])==target){
 6                     int[] a={i,j};
 7                     return a;
 8                 }
 9             }
10         }
11         return null;
12     }
13 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325347573&siteId=291194637