题解 | #旋转数组的最小数字#
旋转数组的最小数字
https://www.nowcoder.com/practice/9f3231a991af4f55b95579b44b7a01ba
function minNumberInRotateArray(rotateArray) { // write code here for(let i=0;i<rotateArray.length;i++){ if(rotateArray[i]>rotateArray[i+1]) return rotateArray[i+1]; } return rotateArray[0]; } module.exports = { minNumberInRotateArray : minNumberInRotateArray };
循环遍历数组,一直往右边查找,只要查找到一个值小于左边的值,那么小于左边的值就为最小值,否则为第一个元素。