Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cf8e53a

Browse files
Merge pull request youngyangyang04#2104 from fwqaaq/patch-25
Update 0377.组合总和IV.md 优化 rust
2 parents 385b650 + b76f5b6 commit cf8e53a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

‎problems/0377.组合总和IV.md‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,17 @@ Rust
269269
```Rust
270270
impl Solution {
271271
pub fn combination_sum4(nums: Vec<i32>, target: i32) -> i32 {
272-
let mut dp = vec![0; target as usize + 1];
272+
let target = target as usize;
273+
let mut dp = vec![0; target + 1];
273274
dp[0] = 1;
274-
for i in 1..=target asusize{
275-
for &j in nums.iter() {
276-
if i asi32>= j {
277-
dp[i] += dp[i-j as usize];
275+
for i in 1..=target {
276+
for &n in &nums {
277+
if i >= nasusize {
278+
dp[i] += dp[i-n as usize];
278279
}
279280
}
280281
}
281-
returndp[targetasusize];
282+
dp[target]
282283
}
283284
}
284285
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /