Skip to content

Commit 5291eac

Browse files
authored
Update last-stone-weight-ii.cpp
1 parent 14b73ce commit 5291eac

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

C++/last-stone-weight-ii.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ class Solution {
55
public:
66
int lastStoneWeightII(vector<int>& stones) {
77
unordered_set<int> dp = {0};
8-
const auto& S = accumulate(stones.cbegin(), stones.cend(), 0);
98
for (const auto& stone : stones) {
109
auto tmp(dp);
1110
for (const auto& i : dp) {
1211
tmp.emplace(i + stone);
1312
}
1413
dp = move(tmp);
1514
};
15+
const auto& S = accumulate(stones.cbegin(), stones.cend(), 0);
1616
auto result = numeric_limits<int>::max();
1717
for (const auto& i : dp) {
1818
result = min(result, abs(i - (S - i)));

0 commit comments

Comments
 (0)