@@ -0,0 +1,1021 @@
+// Solution runs in O(log n) time and O(1) space.%0A// Idea is finding actual min index first, and run binary search based on indices with%0A// that min offset, but look up element based on actual index ((index + offset) %25 nums.length).%0Aclass Solution %7B%0A  public int search(int%5B%5D nums, int target) %7B%0A    int start = 0, end = nums.length - 1;%0A    // Need to consider several approaches.%0A    int min = min(nums);%0A    if (min %3C 0) return -1;%0A    int i = min, j = min + nums.length - 1;%0A    while (i %3C= j) %7B%0A      int mid = (i + j) / 2; // sorted offset%0A      int m = mid %25 nums.length; // actual offset%0A      if (nums%5Bm%5D == target) return m;%0A      if (nums%5Bm%5D %3E target) %7B%0A        j = mid - 1;%0A      %7D else %7B%0A        i = mid + 1;%0A      %7D%0A    %7D%0A    return -1;%0A  %7D%0A%0A  private int min(int%5B%5D nums) %7B%0A    int i = 0, j = nums.length - 1;%0A    while (i %3C= j) %7B%0A      if (i == j) return i;%0A      int mid = (i + j)/2;%0A      if (nums%5Bmid%5D %3C nums%5Bj%5D) %7B%0A        j = mid;%0A      %7D else %7B%0A        i = mid + 1;%0A      %7D%0A    %7D%0A    return -1;%0A  %7D%0A%7D%0A

add solution