You are viewing a single comment's thread. Return to all comments →
JAVA Solution:
int[] arr=cost.stream().mapToInt(Integer::intValue).toArray(); Arrays.sort(arr); int start=0; int end=arr.length-1; while(start<end){ if(arr[start]+arr[end]>money){ end--; } else if(arr[start]+arr[end]<money){ start++; } else{ TreeSet<Integer> res=new TreeSet<>(); res.add(cost.indexOf(arr[start])+1); int pos2=cost.indexOf(arr[end])+1;; if(arr[start]==arr[end]){ cost.remove(cost.indexOf(arr[start])); pos2=cost.indexOf(arr[end])+2; } res.add(pos2); System.out.print(res.first()+" "+res.last()); System.out.println(); break; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Hash Tables: Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
JAVA Solution: