第 32 日:I. 剪绳子
题目链接:https://leetcode-cn.com/problems/jian-sheng-zi-lcof/
题目
解题
-
动态规划
解题思路:
动态规划还是比较容易理解的:
1.创建dp数组,用来存放i
(下标)的最大乘积
2.初始化长度为2
的最大乘积为1
3.后面每次求最大乘积,根据自身和之前以求过的dp数组筛选最大值详细代码如下:
class Solution {
public int cuttingRope(int n) {
int[] dp=new int[n+1];
dp[2]=1;
for(