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.
I don't get it. You iterate through the array only once. What if opposite direction pairs appear after you perform some other deletions?
Stack is a legacy class that should not be used in new code. So this is not best practice. (Deque should be used instead of Stack)
https://stackoverflow.com/questions/37314298/why-stack-extends-vector-in-jdk
sorry for the maybe stupid question, but why reverse the item when using Deque as Stack ?
from the Deque doc: "When a deque is used as a stack, elements are pushed and popped from the beginning of the deque"
why not use addFirst() and removeFirst() then ?
You could use a Deque as a LIFO queue by using
addLast()
andpeekLast()
. Then you don't have to do the reversal.Typically this solution get best running time, but rarely it get worst than 2 for loop statement (slower than 100 * times). Try to run this 1000 times and get 1 worst case.