Type a sort then binarySearch
Type a sort then binarySearch
Answer
Arrays.sort(nums); int idx = Arrays.binarySearch(nums, 5);
binarySearch requires the array to already be sorted. An unsorted input produces undefined (potentially wrong) results.
Type a sort then binarySearch
Type a sort then binarySearch
Answer
Arrays.sort(nums); int idx = Arrays.binarySearch(nums, 5);
binarySearch requires the array to already be sorted. An unsorted input produces undefined (potentially wrong) results.