I am trying to solve a popular problem on leetcode called two sum on my ide(intellij). I am expecting it to print index of values inside the array but its printing a memory address. I did some searching and found that i need to override to string(), i did the override and its still printing the memory address. what am i doing wrong? If anyone can help me out, i would appreciate it. Thank you. :)
import java.util.HashMap;
import java.util.Map;
public class Main {
@Override
public String toString() {
return super.toString();
}
public static void main(String[] args) {
int arr[]={2,7,11,15};
int target= 9;
int result[]=(find(arr,target));
System.out.println(result);
}
public static int[] find(int[] arr,int target){
Map<Integer,Integer> hm =new HashMap<>();
for(int i=0;i<arr.length;i++){
int num= target- arr[i];
if(hm.containsKey(num)){
return new int[]{hm.get(num),i};
}
hm.put(arr[i],i);
}
return new int[]{-1, -1};
}
}