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.
added for all languages
good choice).. the easiest one)
I had the same type of solution but used do { ... } while (n != 0);
Then if n == 0, the loop will still run at least once.
Also note, this type of solution can do a reasonable thing negatives if you keept track of the sign: -1234 goes to -14916.
Finally, the integer parseInt will throw appropriately if there is integer overflow.
I agree! There should probablt be a special case for that happening, wouldn't be too dificult to fix.
Need a test case like the following: {9,10,14,12,13}
This case would fail several of the accepted answers because they check for more than one instance of prev > current as a fail condition.
Thinking there should be a test case where n is 0. A lot of the solutions that don't convert n to a String will throw an exception if 0 is passed in because we try to Integer.parseInt an empty string.
What happens if n is 0?
I'm thinking parseInt("") is going to throw a conniption fit!