We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 69bf54e commit b704b45Copy full SHA for b704b45
solution/033.Search in Rotated Sorted Array/Solution.java
@@ -0,0 +1,17 @@
1
+class Solution {
2
+ public int search(int[] A, int target) {
3
+ if (A == null || A.length == 0) return -1;
4
+ int low = 0,high = A.length - 1;
5
+ while (low <= high) {
6
+ int mid = (low + high) / 2;
7
+ if (target < A[mid]) {
8
+ if (A[mid] >= A[high] && target < A[low]) low = mid + 1;
9
+ else high = mid - 1;
10
+ } else if (target > A[mid]) {
11
+ if (A[low] >= A[mid] && target > A[high]) high = mid - 1;
12
+ else low = mid + 1;
13
+ } else return mid;
14
+ }
15
+ return -1;
16
17
+}
0 commit comments