Skip to content

Commit 04473d1

Browse files
authored
Create Solution.java
1 parent 9eb5b5a commit 04473d1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public int lastStoneWeightII(int[] stones) {
3+
int sum = Arrays.stream(stones).sum();
4+
int n = sum >> 1;
5+
int[] f = new int[n + 1];
6+
for (int stone : stones) {
7+
for (int i = n; i >= stone; --i) {
8+
f[i] = Math.max(f[i], f[i - stone] + stone);
9+
}
10+
}
11+
return sum - 2 * f[n];
12+
}
13+
}

0 commit comments

Comments
 (0)