javac ValidClosers.java
java ValidClosers
- Runtime: O(n)
- Space: O(n)
The solution is a stack implementation, the stack must follow these rules:
openers
get pushed to the stackopeners
will be poped from the stack if theclosers
meet the following conditions:stack
is not empty- The first element on the stack is in
openers
- The
closers
must close theopeners
popped from thestack
stack
must be empty after the string has been processed