I was getting an issue on with map.get(complement),i
On checking the soln its map.get(complement),i+1
what's the +1 for ? I still don't understand?
class Solution {
public int[] twoSum(int[] numbers, int target) {
Map<Integer, Integer> map = new HashMap<>();
for(int i=0;i<numbers.length;i++){
int complement = target - numbers[i];
if(map.containsKey(complement)){
return new int[] {
map.get(complement),i+1
};
}
map.put(numbers[i], i+1);
}
throw new IllegalArgumentException();
}
}Thanks