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.
i dont get that :(
I made this Kata for beginners. It may be trival for you, but it will help beginners.
thank you.
I used vector this time thank you
if there was multiple closest values return first closest value.
A duplicate of https://www.codewars.com/kata/59887207635904314100007b, besides the non-zero value (trivial difference) and returning a different value if closest values from both sides are encountered (also trivial).
Kata never mentions what should be done if there are multiple closest values, or if values from both sides are encountered.
This is not a C++ kata. This is a C kata.
Please use proper C++ constructs for the task, e.g actually using
std::vector
instead ofint[]
(which decays toint *
).Similarly, function naming convention in C++ is either
snake_case
orcamelCase
(the former is more common).//no need to use a loop
a.erase(0,1);
a.erase(a.size()-1,1);
return a;
The auto keyword in C++ automatically detects and assigns a data type to the variable with which it is used. The compiler analyses the variable's data type by looking at its initialization.
so in my case maybe the compiler takes longer time to compile the code but if I write std::string or auto they will do the same job
Can you please tell me if using "auto" is not very resource intensive in large-scale codes?
You did not get exeption "Caught std::exception, what(): stoi"?
I've got same code but avery time get this err and could not realise what's wrong with stoi
Thank you so much
The
*p = 0
adds the null terminator for the string. Same as*p = '\0';
The comma operator is described here. https://en.wikipedia.org/wiki/Comma_operator
the value of the comma line is whatever the last expression evaluated to (in this case it is
string
)So effect is that
will be same as:
Can someone explain to me what happens in the last line? return *p = 0, string;