Hello!
inputArray: [5, 1, 2, 3, 0, 1, 5, 0, 2] I want to create a code that adds numbers sequentially in that array and returns a result when I check for zero.
If possible, I tried to solve it using the accumulate algorithm, but is there a way to check 0 and escape?
autolambda = [&](inta, intb) { return a + b; /* How to escape? */ };
return accumulate(inputArray.begin(), inputArray.end(), 0, lambda);
There was a simpler solution than I thought.
return accumulate(inputArray.begin(), find(inputArray.begin(), inputArray.end(), 0), 0);
© 2024 OneMinuteCode. All rights reserved.