题解 | #旋转数组#
旋转数组
https://www.nowcoder.com/practice/e19927a8fd5d477794dac67096862042
/** * 旋转数组 * @param n int整型 数组长度 * @param m int整型 右移距离 * @param a int整型一维数组 给定数组 * @return int整型一维数组 */ function solve( n , m , a ) { // write code here let len = a.length; let num = n-m ; let b ; if(num > 0){ b = a.splice(num,m); }else { num = len + num; b = a.splice(num, m); } a = b.concat(a); return a; } module.exports = { solve : solve };