Skip to content

Commit

Permalink
Merge pull request youngyangyang04#2104 from fwqaaq/patch-25
Browse files Browse the repository at this point in the history
Update 0377.组合总和Ⅳ.md 优化 rust
  • Loading branch information
youngyangyang04 authored Jun 8, 2023
2 parents 385b650 + b76f5b6 commit cf8e53a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions problems/0377.组合总和Ⅳ.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,17 @@ Rust
```Rust
impl Solution {
pub fn combination_sum4(nums: Vec<i32>, target: i32) -> i32 {
let mut dp = vec![0; target as usize + 1];
let target = target as usize;
let mut dp = vec![0; target + 1];
dp[0] = 1;
for i in 1..=target as usize {
for &j in nums.iter() {
if i as i32 >= j {
dp[i] += dp[i- j as usize];
for i in 1..=target {
for &n in &nums {
if i >= n as usize {
dp[i] += dp[i - n as usize];
}
}
}
return dp[target as usize];
dp[target]
}
}
```
Expand Down

0 comments on commit cf8e53a

Please sign in to comment.