时间复杂度O(n^2) 空间复杂度O(1)
const rorateKstep = (arr = [1,2,3,4,5,6,7],step = 3) => { const length = arr.length for(let i = 0; i < 3;i++){ arr.unshift(arr[arr.length - 1]) arr.length = length } return arr }
时间复杂度O(1) 空间复杂度O(n)
const rorateKstep = (arr = [1,2,3,4,5,6,7],step = 3) => { const length = arr.length arr = arr.slice(-step).concat(arr); arr.length = length return arr }
标签:arr,const,复杂度,step,旋转,length,数组,return From: https://www.cnblogs.com/zhenjianyu/p/17067412.html