We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Can I ask you why? Because I think the condition: <= s.length - m will make the accumulate in belong the size of vector, I dont understand a code with same like you said like this:
int solve(int n, vector < int > s, int d, int m){
int ways = 0;
for(auto it = s.cbegin(); it != s.cend(); ++it){
if(d == std::accumulate(it, it + m, 0))
ways++;
}
return ways;
}
Subarray Division
You are viewing a single comment's thread. Return to all comments →
Can I ask you why? Because I think the condition:
<= s.length - m
will make the accumulate in belong the size of vector, I dont understand a code with same like you said like this:int solve(int n, vector < int > s, int d, int m){ int ways = 0; for(auto it = s.cbegin(); it != s.cend(); ++it){ if(d == std::accumulate(it, it + m, 0)) ways++; } return ways; }