nums = [1,2,4,1,34,6,-1,2]
    for(let i = nums.length - 1; i > 0; i--) {
        let maxIdx = i;
        for(let j = 0; j < i; j++) {
            if(nums[maxIdx] < nums[j]) maxIdx = j;
        }
        if(maxIdx !== i) {
            let temp = nums[maxIdx];
            nums[maxIdx] = nums[i];
            nums[i] = temp;
        }
    }

 

posted on 2018-09-29 19:05  tt-wedos  阅读(236)  评论(0编辑  收藏  举报