Valid Parentheses
Hard
data_structures
algorithms
strings
stack
Description
Determine if an input string of parentheses `(`, `)`, `{`, `}`, `[`, `]` is valid. A string is valid if open brackets must be closed by the same type of brackets, and open brackets must be closed in the correct order. Must use a stack data structure.
Examples
Example1:
Input: '([{}])'
Output: true
Explanation: All brackets are opened and closed correctly.
Example2:
Input: '([)]'
Output: false
Explanation: The square bracket is closed before the curly brace is closed.
Constraints
- Input string contains only the six types of parentheses.
- Must use the Stack principle (LIFO).
Loading...
Test Case 1
Input: "()[]{}"
Output: true
Test Case 2
Input: "([{}])"
Output: true
Test Case 3
Input: "(]"
Output: false
Test Case 4
Input: "{"
Output: false
