102. validate string of parentheses

JavaScriptAlgorithmstring

easy  - accepted / - tried

Given a string containing only following characters:

  1. parentheses : ( or )
  2. brackets: [ or ]
  3. braces: { or }

write a function to determine if they are valid.

By 'valid', it means all should be rightly paired, and with the valid order.


validate('{}[]()') 
// true

validate('{[()]}') 
// true

validate('{[}]') 
// false, they are not in the right order

validate('{}}') 
// false, last `}` is not paired with `{`

Follow-up

What is time & space complexity of your approach ? Can you do it better?

Always try to find a better approach.

(65)