problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::integer_break::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static int integerBreak (int n)
 

详细描述

在文件 leetcode.h2539 行定义.

成员函数说明

◆ integerBreak()

int leetcode::integer_break::Solution::integerBreak ( int  n)
static

在文件 leetcode.cpp6831 行定义.

6831 {
6832 // dp[i] is the maximum product of i
6833 vector<int> dp(n + 1);
6834 // dp[i] = max(dp[i], dp[j] * dp[i - j])
6835 dp[2] = 1;
6836 dp[1] = 1;
6837 for(int i = 3; i <= n; i++) {
6838 for(int j = 1; j < i; j++) {
6839 dp[i] = max(dp[i], dp[j] * dp[i - j]);
6840 dp[i] = max(dp[i], j * dp[i - j]);
6841 dp[i] = max(dp[i], dp[j] * (i - j));
6842 dp[i] = max(dp[i], j * (i - j));
6843 }
6844 }
6845 return dp[n];
6846 }

被这些函数引用 leetcode::integer_break::TEST().


该类的文档由以下文件生成: