Skip to content

Commit 34f30bf

Browse files
Day18-q2 solution added in python #409
1 parent 3f2cd02 commit 34f30bf

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Python code:
2+
```
3+
class Solution {
4+
public int search(int[] A, int B) {
5+
int l = 0;
6+
int r = A.length-1;
7+
int m;
8+
while(l<=r){
9+
m = (l+r)/2;
10+
if(A[m] == B) return m;
11+
if(A[m]>=A[0]){
12+
if(B>=A[0] && B<=A[m]) r = m-1;
13+
else l = m+1;
14+
}else{
15+
if(B>=A[m] && B<=A[A.length-1]) l = m+1;
16+
else r = m-1;
17+
}
18+
19+
}
20+
return -1;
21+
}
22+
}
23+
```

0 commit comments

Comments
 (0)