Created
March 4, 2014 06:42
-
-
Save rayjcwu/9341439 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
| public int binarySearch(int []num, int target) { | |
| int min = 0; | |
| int max = num.length - 1; | |
| while (min <= max) { | |
| int mid = min + (max - min)/2; | |
| if (num[mid] == target) { | |
| return mid; | |
| } else if (target < num[mid]) { | |
| max = mid - 1; | |
| } else { | |
| min = mid + 1; | |
| } | |
| } | |
| return -1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment