JS
/**
* @param {number[]} numbers
* @return {number}
*/
var minArray = function(numbers) {
if(!numbers){
return []
}
for(let i = 0; i < numbersLength; i++){
if(numbers[i] > numbers[i + 1]){
return numbers[i + 1]
}
}
return numbers[0]
};
时间复杂度On
空间复杂度O1
顺便复习一下快速排序 JS
function quickSort(arr){
if(arr.length<=1){
return arr;
}
let left= [];
let right = [];
let baseindex = Math.floor(arr.length/2);
let base = arr.splice(baseindex,1)[0];
for(let i=0;i<arr.length;i++){
if(arr[i]<=base){
left.push(arr[i]);
}else{
right.push(arr[i]);
}
}
return quickSort(left).concat((base),quickSort(right));
}