java solution to Valid Parentheses