1. 贪心
1.1
2. 二分查找
public int binarySearch(int[] array, int target) {
int left = 0, right = array.length - 1;
while (left < right) {
int mid = (left + right) / 2;
if (array[mid] == target) {
return mid;
}
if (array[mid] < target) {
left = mid + 1;
} else {
right = right - 1;
}
}
return -1;
}
2.1 sqrt(x)(69)
- 二分查找
- 牛顿迭代法