1二分查找
int mid = (max-min)>>1+min;
if (mid>=0&&min<=max&&mid<=max){
if (search[mid]==target){
return mid;
}
if (search[mid]>target){
return towPointSerch2(search,target,min,mid-1);
}else {
return towPointSerch2(search,target,mid+1,max);
}
}
return -1;
2循环比赛
if (n==1){
arr[n-1][n-1]=1;
}else {
int m = n>>1;
CircleCom(arr,m);
//右上角的方格数据
for (int i = 0;i<m;i++){
for (int j = m;j<n;j++){
arr[i][j] = arr[i][j-m]+m;
}
}
//左下角
for (int i = m;i<n;i++){
for (int j = 0;j<m;j++){
arr[i][j] = arr[i-m][j+m];
}
}
//右下角的方格数据
for (int i = m;i<n;i++){
for (int j = m;j<n;j++){
arr[i][j] = arr[i-m][j-m];
}
}
}
3汉诺塔(还是不太懂咋移动的汉诺塔)
private static void haNoi(String a,String b,String c,int n){
if (n==1){
move(n,a,c);
}else {
haNoi(a,c,b,n-1);
move(n,a,c);
haNoi(b,a,c,n-1);
}
}
private static void move(int n,String i,String j){
System.out.println("把第"+n+"个圆盘从"+i+"移动到"+j);
}
4零钱兑换
int[] road = new int[account+1];
for (int i = 1;i<road.length;i++){
road[i] = 1000;
}
for (int i = 1;i<road.length;i++){
for (int j = 0;j<coins.length;j++){
if (coins[j]<=i){
road[i] = Math.min(road[i],road[i-coins[j]]+1);
}
}
}
return road[account]==1000?-1:road[account];
5最大子序列和
int maxSum=0;int thisSum=0;
for(int i=0;i<a.length;i++){
thisSum+=a[i];
if(thisSum>maxSum){
maxSum=thisSum;
}else if(thisSum<0){
thisSum=0;
}
}
return maxSum;