Created
March 22, 2015 11:24
-
-
Save nikoncode/093bc0aebbfe191345d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int[] arr = {1,2,7,4,5,7,5,7,6,7,0,-1,22,15}; | |
| Arrays.sort(arr); | |
| for (int i = 0; i < arr.length; i++) { | |
| System.out.println(i + " : " + arr[i]); | |
| } | |
| System.out.println("RES:"); | |
| int match = Arrays.binarySearch(arr, 7); | |
| if (match >= 0) { | |
| int first = match; | |
| int last = match; | |
| while (first > 0 && arr[first - 1] == arr[match]) | |
| --first; | |
| while (last < arr.length - 1 && arr[last+1] == arr[match]) | |
| ++last; | |
| System.out.println("Matches " + first + " " + last); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment