Practice/Google/Leetcode 20. Valid Parentheses
CodingMust
Given a string containing only the characters (, ), {, }, [, and ], determine if the input string represents a valid bracket sequence.
A string is considered valid if:
true if the string is valid, false otherwise(), square brackets [], and curly braces \{\}true)0 <= s.length <= 10^4(, ), {, }, [, ]Example 1:
Input: s = "()" Output: true Explanation: A single pair of parentheses is valid.
Example 2:
Input: s = "()[]{}" Output: true Explanation: Multiple bracket pairs in sequence, all properly matched.
Example 3:
Input: s = "(]" Output: false Explanation: The opening parenthesis is incorrectly matched with a closing square bracket.
Example 4:
Input: s = "{[]}" Output: true Explanation: Square brackets are properly nested within curly braces.
Example 5:
Input: s = "([)]" Output: false Explanation: The brackets are interleaved incorrectly. The opening square bracket is inside the parentheses but its closing bracket is outside.