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 bf2d349

Browse files
Merge pull request youngyangyang04#2085 from fwqaaq/patch-42
Update 1049.最后一块石头的重量II.md about rust
2 parents 9b7bedf + 38503dd commit bf2d349

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

‎problems/1049.最后一块石头的重量II.md‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,23 @@ object Solution {
379379
}
380380
```
381381

382-
383-
382+
### Rust
383+
384+
```rust
385+
impl Solution {
386+
pub fn last_stone_weight_ii(stones: Vec<i32>) -> i32 {
387+
let sum = stones.iter().sum::<i32>();
388+
let target = sum as usize / 2;
389+
let mut dp = vec![0; target + 1];
390+
for s in stones {
391+
for j in (s as usize..=target).rev() {
392+
dp[j] = dp[j].max(dp[j - s as usize] + s);
393+
}
394+
}
395+
sum - dp[target] * 2
396+
}
397+
}
398+
```
384399

385400
<p align="center">
386401
<a href="https://programmercarl.com/other/kstar.html" target="_blank">

0 commit comments

Comments
(0)

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