递归乘法
直接上代码:
/** * @param {number} A * @param {number} B * @return {number} */ var multiply = function(A, B) { if(A === 0 || B === 0)return 0 arr = [0] for(let i = 1; i <= B; i++){ arr[i] = arr[i - 1] + A } return arr[B] };
汉诺塔
标签:12,return,金典,move,number,param,---,pop From: https://www.cnblogs.com/dgqp/p/17341995.html代码:
/** * @param {number[]} A * @param {number[]} B * @param {number[]} C * @return {void} Do not return anything, modify C in-place instead. */ var hanota = function(A, B, C) { const n = A.length const move = (n, A, B, C) => { if(n === 1){ C.push(A.pop()) return } // 将A中的n-1个移动到B move(n - 1, A, C, B) // 将A剩余的一个移动到C C.push(A.pop()) // 将B中的n-1个移动到C move(n - 1, B, A, C) } move(n, A, B, C) };