From 0076152aecfff72cae6c53f4c36b29faee62e47d Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Mon, 15 Jan 2024 09:52:08 +0800 Subject: [PATCH] =?UTF-8?q?Update=200343.=E6=95=B4=E6=95=B0=E6=8B=86?= =?UTF-8?q?=E5=88=86=EF=BC=8C=E6=B7=BB=E5=8A=A0C#?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0343.整数拆分.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/problems/0343.整数拆分.md b/problems/0343.整数拆分.md index 2e17caf5..bbbd5c63 100644 --- a/problems/0343.整数拆分.md +++ b/problems/0343.整数拆分.md @@ -496,6 +496,25 @@ class Solution { } } ``` +### C# +```csharp +public class Solution +{ + public int IntegerBreak(int n) + { + int[] dp = new int[n + 1]; + dp[2] = 1; + for (int i = 3; i <= n; i++) + { + for (int j = 1; j <= i / 2; j++) + { + dp[i] = Math.Max(dp[i],Math.Max(j*(i-j),j*dp[i-j])); + } + } + return dp[n]; + } +} +```