02递归查找排序
二分查找 递归/循环
10种排序:插入 希尔 选择 堆 冒泡 快速 归并 计数 桶 基数
小白上楼梯
旋转数组的最小数字
在有空字符串的有序字符串数组中查找
找出最长连续递增子序列
快速幂
二分查找 递归/循环
public static int search(int[] arr, int target,int low, int high){
int mid = low + (high - low)/2;
if(arr[mid]==target){
return mid;
}else if(arr[mid]<target){
return search(arr,target,mid+1,high);
}else{
return search(arr,target,low,mid-1);
}
}
int[] arr = {0,1,2,3,4,5,6,7,8,9,10};
int target = 7;
int res = -1;
int low = 0, high = arr.length - 1;
while(low<=high){
int mid = low + (high-low)/2;
if(arr[mid]==target){
res = mid;
break;
}else if(arr[mid] < target){
low = mid + 1;
}else{
high = mid - 1;
}
}
System.out.println(res);
10种排序:插入 希尔 选择 堆 冒泡 快速 归并 计数 桶 基数(第三章写)
小白上楼梯
public static int getStep(int n){
if(n<=0)return 0;
if(n==1)return 1;
if(n==2)return 2;
if(n==3)return 4;
else{
return getStep(n-1)+getStep(n-2)+getStep(n-3);
}
}
旋转数组的最小数字 Leetcode153
public int findMin(int[] nums) {
int n = nums.length;
int low = 0,high = n-1;
while(low<high){
int mid = low + (high-low)/2;
if(nums[mid]<nums[high]){
high = mid;
}else{
low = mid+1;
}
}
return nums[high];
}
在有空字符串的有序字符串数组中查找
(我觉得可以把空字符串赋值成左边或右边第一个有值的字符串)
找出最长连续递增子序列
快速幂 (要考虑负数) Leetcode50
class Solution {
public double myPow(double x, int n) {
long N = n;
return N >= 0 ? quickMul(x, N) : 1.0 / quickMul(x, -N);
}
public double quickMul(double x, long N) {
if (N == 0) {
return 1.0;
}
double y = quickMul(x, N / 2);
return N % 2 == 0 ? y * y : y * y * x;
}
}