Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Please use a spoiler flag next time, your comments are visible from the codewars homepage. I've added the spoiler flag to your comment for you.
This comment is hidden because it contains spoiler information about the solution
yep. Return {0,0}
Simply re-try.
The tests are actually harder, I have executed the max data test multiple times.
This comment is hidden because it contains spoiler information about the solution
One can further improve this by not creating second if-statement. If you sum negatives and add 0 to them, it doesn't affect the sum. Thanks for teaching these temporary vectors :)
Does this still work if the input vector is {0, 0, 0, 0, 0}?
If anyone else is also interested, I found a reference to this c++ construct of list initialization: http://en.cppreference.com/w/cpp/language/list_initialization
Hello, bolin-hsu and thank you!
Curly brackets means that we create temporary object, in our case it's vector consists of 2 elements. Note, it's new feature of C++14.
Have a nice day!
Nice concise code! What is the meaning of the curly bracket in the return statements?
I have missed it "&", so a tiny remark: "int sum(std::vector& numbers)"
And of course, we could use "for" cycle to reach more performance and one more note it's passing the vector by value. To reach more performance we should used passing by link. So.. vector f(vector& input) is better way.