添加 0343.整数拆分 Rust版本

添加 0343.整数拆分 Rust版本
This commit is contained in:
cezarbbb
2022-08-07 19:34:04 +08:00
parent bbd83a7b1b
commit 60f3ad665b

View File

@ -299,6 +299,27 @@ function integerBreak(n: number): number {
};
```
### Rust
```Rust
impl Solution {
fn max(a: i32, b: i32) -> i32{
if a > b { a } else { b }
}
pub fn integer_break(n: i32) -> i32 {
let n = n as usize;
let mut dp = vec![0; n + 1];
dp[2] = 1;
for i in 3..=n {
for j in 1..i - 1 {
dp[i] = Self::max(dp[i], Self::max(((i - j) * j) as i32, dp[i - j] * j as i32));
}
}
dp[n]
}
}
```
### C
```c