Valid Parentheses
Easy · String, Stack
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
An input string is valid if:
Example 1
Input: s = "()" Output: true
Example 2
Input: s = "()[]{}"
Output: trueExample 3
Input: s = "(]" Output: false
Example 4
Input: s = "([])" Output: true
Example 5
Input: s = "([)]" Output: false
Constraints
- 1 <= s.length <= 104
- s consists of parentheses only '()[]{}'.
Starter code (python)
class Solution(object):
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
Related problems
- Longest Substring Without Repeating Characters (Medium)
- Longest Palindromic Substring (Medium)
- Roman to Integer (Easy)
Previous: Remove Nth Node From End of List · Next: Merge Two Sorted Lists · All problems
Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.