We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
针对文中代码修改如下,见注释处 private static int search(int[] data,int l,int r,int target){ int mid; //注意:此处循环条件为<=,若无=则无法查找数组起始处数据 while(l<=r){ mid=(l+r)/2; if(data[mid]==target){ return mid; }else if(data[mid]<target){ l=mid+1; }else{ r=mid; } } return -1; } private static int searchDfs(int[] data,int l,int r,int target){ //注意:此处循环条件为>,若有=则无法查找数组起始处数据 if(l>r){ return -1; } int mid=(l+r)/2; if(target==data[mid]){ return mid; }else if(target>data[mid]){ return searchDfs(data,mid+1,r,target); }else{ return searchDfs(data,l,mid,target); } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
针对文中代码修改如下,见注释处
private static int search(int[] data,int l,int r,int target){
int mid;
//注意:此处循环条件为<=,若无=则无法查找数组起始处数据
while(l<=r){
mid=(l+r)/2;
if(data[mid]==target){
return mid;
}else if(data[mid]<target){
l=mid+1;
}else{
r=mid;
}
}
return -1;
}
private static int searchDfs(int[] data,int l,int r,int target){
//注意:此处循环条件为>,若有=则无法查找数组起始处数据
if(l>r){
return -1;
}
int mid=(l+r)/2;
if(target==data[mid]){
return mid;
}else if(target>data[mid]){
return searchDfs(data,mid+1,r,target);
}else{
return searchDfs(data,l,mid,target);
}
}
The text was updated successfully, but these errors were encountered: