We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents a4465c0 + 5257958 commit fbb5991Copy full SHA for fbb5991
problems/1049.最后一块石头的重量II.md
@@ -219,7 +219,28 @@ func max(a, b int) int {
219
}
220
```
221
222
+JavaScript版本
223
+
224
+```javascript
225
+/**
226
+ * @param {number[]} stones
227
+ * @return {number}
228
+ */
229
+var lastStoneWeightII = function (stones) {
230
+ let sum = stones.reduce((s, n) => s + n);
231
232
+ let dpLen = Math.floor(sum / 2);
233
+ let dp = new Array(dpLen + 1).fill(0);
234
235
+ for (let i = 0; i < stones.length; ++i) {
236
+ for (let j = dpLen; j >= stones[i]; --j) {
237
+ dp[j] = Math.max(dp[j], dp[j - stones[i]] + stones[i]);
238
+ }
239
240
241
+ return sum - dp[dpLen] - dp[dpLen];
242
+};
243
+```
244
245
-----------------------
246
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
0 commit comments