MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / search

Method search

src/com/blankj/medium/_0033/Solution.java:12–26  ·  view source on GitHub ↗
(int[] nums, int target)

Source from the content-addressed store, hash-verified

10 */
11public class Solution {
12 public int search(int[] nums, int target) {
13 int l = 0, r = nums.length - 1, mid;
14 while (l <= r) {
15 mid = l + r >>> 1;
16 if (nums[mid] == target) return mid;
17 else if (nums[mid] >= nums[l]) {
18 if (nums[l] <= target && target < nums[mid]) r = mid - 1;
19 else l = mid + 1;
20 } else {
21 if (nums[mid] < target && target <= nums[r]) l = mid + 1;
22 else r = mid - 1;
23 }
24 }
25 return -1;
26 }
27
28 public static void main(String[] args) {
29 Solution solution = new Solution();

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected