You are viewing a single comment's thread. Return to all comments →
o(n), assertions, performance, c++))
int birthday(vector<int> s, int d, int m) { assert(s.size() > 0 && d > 0 && m > 0); int sum = accumulate(s.cbegin(), s.cbegin() + m, 0); int r = 0; for (int i = 0, e = s.size() - m; i < e; ++i) { if (sum == d) { ++r; } sum += s[i + m]; sum -= s[i]; } if (sum == d) { ++r; } return r; }
Seems like cookies are disabled on this browser, please enable them to open this website
Subarray Division 2
You are viewing a single comment's thread. Return to all comments →
o(n), assertions, performance, c++))