rewrite leetcode valid parentheses