Site icon Wander In Dev

Valid Parentheses (LeetCode #20)

Challenge Statement

Constraints

Example 1:

Input: s = "()"

Output: True

Example 2:

Input: s = "()[]{}"

Output: True

Example 3:

Input: s = "(]"

Output: False

Solution

Below is my solution and some test cases. The solution has a linear time complexity of O(n) and a linear space complexity O(n), where n is the length of the string s.

Exit mobile version