
Problem
Solution
Submissions
Valid Parentheses
Certification: Advanced Level
Accuracy: 37.5%
Submissions: 8
Points: 8
Write a C# function to determine if a given string contains valid parentheses. An input string is valid if: 1. Open brackets must be closed by the same type of brackets. 2. Open brackets must be closed in the correct order. 3. Every close bracket has a corresponding open bracket of the same type.
Example 1
- Input: s = "()"
- Output: true
- Explanation:
- The string contains one pair of parentheses that open and close correctly.
Example 2
- Input: s = "([)]"
- Output: false
- Explanation:
- The brackets are not closed in the correct order (closing ) before closing ]).
Constraints
- 1 ≤ s.length ≤ 10^4
- s consists of only '(', ')', '{', '}', '[', and ']'
- Time Complexity: O(n)
- Space Complexity: O(n)
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Use a stack data structure to track opening brackets
- When encountering a closing bracket, check if it matches the most recent opening bracket
- The string is valid if all brackets are matched and closed in the correct order
- If the stack is empty at the end and all characters have been processed, the string is valid