[Valid Parentheses] Some improvements

1. check invalid characters
2. check invalid string length
3. reduce redundant code to clarify the logic