/** * @param {number[]} nums * @param {number} target * @return {number} */ const searchInsert = function (nums, target) { }; /* 直接使用二分查找,二分查找没什么好说的,但是这个题目中target不一定存在nums中,所以需要设置一个pos遍历来保存,target应该插入的位置, 我们只需在target < nums[mid]的时候设置一次就行,初始化pos的index=nums.length */ function f2(nums, target) { let pos = nums.length; let left = 0; let right = nums.length - 1; // 二分查找知道left>right结束查找 while (left <= right) { const mid = Math.floor((left + right) / 2); // 如果target