Solved longest valid parentheses problem.