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.
It's because numbers.size() returns a size_t (unsigned int), so when the array is empty numbers.size() - 1 is a large unsigned number (0xFFFFFFFF). Then the for loop executes that number of times and an invalid array index is used.
This comment is hidden because it contains spoiler information about the solution
still does not work. using exactly what you did and still having a segmentation fault. makes no sense.
Well if you got a SIGSEGV (signal: segmentation violation), then it's likely that your program tried to access a spot in the vector numbers that was out of bounds. This might be because:
a) you used ++i in the for loop control instead of i++
or
b) you didn't include the -1 in the for loop control (needed to stay in bounds when grabbing [i+1] inside the loop)
Hope this was helpful!
Hello! Recently, I tried to solve the problem with the similar method, but it told me "Process exited prematurely with a SIGSEGV signal. "
So, if you know the reason, could you please tell me? Thanks.