All Problems
#3 easy stacks-queues

Valid Parentheses

Given a string s containing just the characters (, ), {, }, [ and ], determine if the input string is valid.

A string is valid if: open brackets are closed by the same type of brackets, and open brackets are closed in the correct order.

Example 1
Input:  s = "()"
Output: true
Example 2
Input:  s = "()[]{}"
Output: true
Example 3
Input:  s = "(]"
Output: false
Example 4
Input:  s = "([)]"
Output: false
Constraints:
1 <= s.length <= 10^4 s consists of parentheses only.
Hint 1: Use a stack — push opening brackets, pop and compare when you see a closing bracket.
Hint 2: If the stack is empty when you need to pop, the string is invalid.
Run your code to see AI analysis