Solution to the valid parentheses problem.