rewrite leetcode longest valid parentheses