搜索旋转排序数组
搜索旋转排序数组
search(nums, target){ let left = 0; let right = nums.length - 1; while(left < right){ let mid = Math.floor((left + right) / 2); if((nums[0] > target) ^ (nums[0] > nums[mid]) ^ (target > nums[mid])) left = mid + 1; else right = mid; } return left === right && nums[left] === target ? left : -1; },
算法 文章被收录于专栏
JavaScript算法