![]() ![]() ![]() Given a collision with ASTs with equal value, remove both ASTs.A collision occurs when prev is positive and cur is negative. Using the current cur and previous prev values, check whether a collision will occur.Start curIndex at the top of the stack and check the stack until curIndex is at the second element of the stack, thus checking for all possible AST collisions.Build ArrayList used as a stack and add the AST values to the stack.However, I'm looking to improve speed and memory performance. The solution performs as expected in terms of achieving the correct results. The 5 and 10 never collide.Ĭreate a stack using an ArrayList to compare asteroid (AST) direction, values, and remove ASTs. Smaller ASTs explode (are deleted), the same size both explode, and same direction ASTs do nothingĮxplanation: The 10 and -5 collide resulting in 10. ![]() Negative numbers move left, positive numbers move right.Is this a performant strategy to implement a stack in Kotlin to compare and delete values? ExpectĬreate a stack in order to compare an array of asteroids (ASTs) and handle collisions (deletions), returning the final array of ASTs after collisions. ![]()
0 Comments
Leave a Reply. |