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.
OMG bro,you show me a new method to play this!That's so interesting!
Almost. If itemCount could be zero, then that fails. Use
I don't remember if zero is allowed in the statement, but it should just be a habit in Java, C and C++ to avoid negative arguments to %.
Wow, You have just shown me that simple task can have awesome and unobvious solutions :)
It should handle the edge cases, e.g. zero page size (itemsPerPage)
no need for else statemens if you return before anyway
This comment is hidden because it contains spoiler information about the solution
Hi @steffan153, I'm a beginner in java and I've never seen "<<", could you explain ? The mentioned doc didn't enlighten me a lot... Thanks :)
agreed! but good readability though
The last line at pageItemCount should be
return (itemCount - 1) % itemsPerPage + 1;
Ideally it should be something like this:
int remainingPages = itemCount() % itemsPerPage;
if(remainingPages == 0 || pageIndex < pageCount() - 1) return itemsPerPage;
else return remainingPages;
I noticed too, this solution will fail for scenarios when itemsPerPage completely divides totalPages
Bit shift is awesome. Nice job
That's a bitwise operator - the left bit shift.
What kind of magic is this?
Nice! That is Floyd's cycle-finding algorithm. Check out this wikipedia article for more info.
Loading more items...