大廠學(xué)院擁抱云原生
const binarySearch = (nums, target) => {
?if (nums == null || nums.length == 0) {
? ?return -1;
?}
?let start = 0;
?let end = nums.length - 1;
?while (start + 1 < end) {
? ?let mid = Math.floor((start + end) / 2);
? ?if (target > nums[mid]) {
? ? ?start = mid;
? ?} else {
? ? ?end = mid;
? ?}
?}
標(biāo)簽: