Skip to content

Instantly share code, notes, and snippets.

@pablohdzvizcarra
Created February 6, 2025 13:09
Show Gist options
  • Save pablohdzvizcarra/34a7a98bc78696e86e0ac57a9e33ee14 to your computer and use it in GitHub Desktop.
Save pablohdzvizcarra/34a7a98bc78696e86e0ac57a9e33ee14 to your computer and use it in GitHub Desktop.
Strange binary sort algorithm implementation, very weird
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