I found this line very confusing:
return new int[] {};
Are the two curly brackets referencing something in memory? Here's the full code:
class Solution {
public int[] twoSum(int[] nums, int target) {
HashMap<Integer, Integer> prevMap = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
int num = nums[i];
int diff = target - num; //En diff, iremos restando el num al Objetivo
if (prevMap.containsKey(diff)) {
return new int[] { prevMap.get(diff), i };
}
prevMap.put(num, i);
}
return new int[] {};
}
}