Solve leetcode problem to check valid parentheses string.