数据结构算法学习
二分排序/**
* @Param {number} x
* @Return {number}
*/
var mySqrt = function(x) {
let left = 0;
let right = x;
while(left <= right) {
let mid = Math.round((left + right) / 2);
if (x === result) {
return mid
} else if(x < result) {
right = mid - 1;
} else {
left = mid + 1;
}
}
return -1;
};
页:
[1]