DP solution to longestValidParentheses