Skip to content

Commit 02a8298

Browse files
authored
Update final-value-of-variable-after-performing-operations.cpp
1 parent 15672b7 commit 02a8298

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

C++/final-value-of-variable-after-performing-operations.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@
44
class Solution {
55
public:
66
int finalValueAfterOperations(vector<string>& operations) {
7-
int result = 0;
8-
for (const auto& op : operations) {
9-
if (op[1] == '+') {
10-
++result;
11-
} else {
12-
--result;
13-
}
14-
}
15-
return result;
7+
return accumulate(cbegin(operations), cend(operations), 0,
8+
[](const auto& total, const auto& x) {
9+
return total + ((x[1] == '+') ? 1 : -1);
10+
});
1611
}
1712
};

0 commit comments

Comments
 (0)