Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
28 lines (26 loc) · 714 Bytes

File metadata and controls

28 lines (26 loc) · 714 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package other;
/**
* 神策数据 面试手写算法题1 - 折半查找的实现
*
* @author 刘壮飞
* https://github.com/zfman.
* https://blog.csdn.net/lzhuangfei.
*/
public class ShenCeInterview1 {
public int find(int[] arr,int l,int r,int val){
if(l>r) return -1;
int middle=(l+r)/2;
if(val>arr[middle]) return find(arr,middle+1,r,val);
else if(val<arr[middle]) return find(arr,l,middle-1,val);
else{
return middle;
}
}
public static void main(String[] args){
int[] a={
1,3,5,9,10,20,33
};
int index=new ShenCeInterview1().find(a,0,a.length,33);
System.out.println(index);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.