leetcode longest valid parentheses refactoring