Given a string containing only the characters '(', ')', '{', '}', '[' and ']', determine whether the string is valid — every opening bracket must be closed by the same type of bracket, and brackets must close in the correct order.
s = "()[]{}"trues = "(]"falseTry it now — no sign-up needed. Write your solution in Python or JavaScript, run it against test cases, and submit for a verdict, right in your browser.
Open the editor →A stack is last-in-first-out — the most recently added item is the first one removed. It's the natural fit whenever "the most recent unmatched thing" matters, like nested brackets or undo history.
Original problem on LeetCode ↗