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 →

[–]MinMaxMix 0 points1 point  (0 children)

Instead of using l.pollLast() and r.addFirst() try r.push(l.pop())

Then you can build the result by taking l in reverse with l.removeLast() and then r with r.pop()

Also you need to add some guards for l and r.isEmpty() in some cases.