forked from SnowScriptWinterOfCode/LeetCode_Q
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Day18-q2 solution added in python SnowScriptWinterOfCode#409
- Loading branch information
1 parent
3f2cd02
commit 34f30bf
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
Day-18/q2: Search in Rotated Sorted Array/Tech-neophyte--p.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
## Python code: | ||
``` | ||
class Solution { | ||
public int search(int[] A, int B) { | ||
int l = 0; | ||
int r = A.length-1; | ||
int m; | ||
while(l<=r){ | ||
m = (l+r)/2; | ||
if(A[m] == B) return m; | ||
if(A[m]>=A[0]){ | ||
if(B>=A[0] && B<=A[m]) r = m-1; | ||
else l = m+1; | ||
}else{ | ||
if(B>=A[m] && B<=A[A.length-1]) l = m+1; | ||
else r = m-1; | ||
} | ||
} | ||
return -1; | ||
} | ||
} | ||
``` |