class Solution {
HashMap<Integer, Integer>hm ;
public int[] twoSum(int[] nums, int t) {
int [] ans = new int[2] ;
hm = new HashMap<Integer, Integer>();
for(int i = 0 ; i < nums.length ; i++) {
if(hm.containsKey(t-nums[i])) {
ans[1] = i;
ans[0] = hm.get(t-nums[i]);
}
hm.put(nums[i],i );
}
return ans;
}
}
class Solution {
public int[] twoSum(int[] nums, int target) {
HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>();
for ( int i = 0; i < nums.length; i++) {
hm.put(nums[i], i);
}
for(int i = 0 ; i < nums.length;i++) {
if(hm.containsKey(target-nums[i])) {
if(i!=hm.get(target-nums[i])){
int arr [] = {i,hm.get(target-nums[i])};
return arr;}
}
}
return null;
}
}