#include <vector> #include <numeric> int sum(std::vector<int>& v) { return v.size() == 0 ? -1 : v.size() == 1 ? v[0] : std::accumulate(v.begin(), v.end(), 0); }
- #include <vector>
- #include <numeric>
- int sum(std::vector<int>& v) {
int len = v.size();return len == 0 ? -1: len == 1 ? v[0]- return v.size() == 0 ? -1
- : v.size() == 1 ? v[0]
- : std::accumulate(v.begin(), v.end(), 0);
- }