跳水板
代码:
/** * @param {number} shorter * @param {number} longer * @param {number} k * @return {number[]} */ var divingBoard = function(shorter, longer, k) { if(k === 0) return [] if(shorter === longer)return [k * shorter] let res = [] for(let i = 0; i <= k; i++){ res.push(longer * i + shorter * (k - i)) } return res };
连续数列
标签:shorter,return,22,nums,金典,number,param,---,dp From: https://www.cnblogs.com/dgqp/p/17375510.html思路:
动态规划问题:
动态转换方程:
\[dp[i] = dp[i - 1] < 0 ? nums[i] : dp[i - 1] + nums[i] \]初始状态:
dp[0] = nums[0]
/** * @param {number[]} nums * @return {number} */ var maxSubArray = function(nums) { dp = [nums[0]] for(let i = 1; i < nums.length; i++){ dp[i] = dp[i - 1] < 0 ? nums[i] : dp[i - 1] + nums[i] } return Math.max(...dp) };