From b76f5b6bffc6f53d81c7afdd6f05853f0577d68e Mon Sep 17 00:00:00 2001 From: fwqaaq Date: Sat, 27 May 2023 23:14:11 +0800 Subject: [PATCH] =?UTF-8?q?Update=200377.=E7=BB=84=E5=90=88=E6=80=BB?= =?UTF-8?q?=E5=92=8C=E2=85=A3.md=20=E4=BC=98=E5=8C=96=20rust?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\220\210\346\200\273\345\222\214\342\205\243.md" | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git "a/problems/0377.\347\273\204\345\220\210\346\200\273\345\222\214\342\205\243.md" "b/problems/0377.\347\273\204\345\220\210\346\200\273\345\222\214\342\205\243.md" index ee65972371..ec57906087 100644 --- "a/problems/0377.\347\273\204\345\220\210\346\200\273\345\222\214\342\205\243.md" +++ "b/problems/0377.\347\273\204\345\220\210\346\200\273\345\222\214\342\205\243.md" @@ -253,16 +253,17 @@ Rust ```Rust impl Solution { pub fn combination_sum4(nums: Vec, 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] } } ```