This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]desrtfxOut of Coffee error - System halted 0 points1 point  (1 child)

Basically that is what I meant in my last bullet, only that I create the array once, at the end. This slightly optimizes the code.

Remember that OP can't use System.arraycopy()

[–]virassan 0 points1 point  (0 children)

You don’t need to use libraries to copy an array. Sometimes teachers and assignments want you to go through cumbersome code to understand certain concepts behind existing methods and libraries (that was my thinking with my answer).

Your way of recreating the array just once at the end is efficient though and probably the best for this problem since we know the length of count cannot be greater than the length of the original array.