dsa · easy

Valid Parentheses

GreyOrangeStringStackFoundation

Given a string s containing just the characters (, ), {, }, [ and ], determine if the input string is valid.

Arguments

An input 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.

**Example 1:** `` Input: s = "()[]{}" Output: true ` **Example 2:** ` Input: s = "(]" Output: false ``

Constraints

1 <= s.length <= 4*10^4 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
()[]{}

Expected:
true

Example 2

Input:
(]

Expected:
false

Open in the Dojo editor