Created
February 6, 2025 13:09
-
-
Save pablohdzvizcarra/34a7a98bc78696e86e0ac57a9e33ee14 to your computer and use it in GitHub Desktop.
Strange binary sort algorithm implementation, very weird
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
class Solution { | |
public int search(int[] nums, int target) { | |
int left = 0; | |
int right = nums.length - 1; | |
int result = -1; | |
int n = nums.length; | |
while (n >= 1) { | |
int middle = (left + right) / 2; | |
if (target == nums[middle]) { | |
return middle; | |
} else if (target < nums[middle]) { | |
right = middle - 1; | |
} else if (target > nums[middle]) { | |
left = middle + 1; | |
} | |
n = n / 2; | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment