Balanced Parentheses Checker
Given a string containing only the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. A string is considered valid if brackets open and close correctly in the correct order. For example, '()' and '()[]{}' are valid, but '(]' and '([)]' are not.
[ "()" ]
Explanation. Simple pair of parentheses, which are correctly formatted.
[ "()[]{}" ]
Explanation. Multiple types of brackets, all correctly formatted and closed.
[ "(]" ]
Explanation. The parentheses are closed in the incorrect order.
[ "([)]" ]
Explanation. The brackets are not closed in the correct nested order.
[ "{[]}" ]
Explanation. All types of brackets are used and each is properly nested and closed.
Follow-up: Can you extend your solution to include other types of brackets or different characters?
The input string will only contain the characters '(', ')', '{', '}', '[' and ']'.
- Views
- 4