Valid Parentheses

EasyStack

Description

Given a string `s` containing just the characters `(`, `)`, `{`, `}`, `[` and `]`, determine if the input string is **valid**. A string is valid if: open brackets are closed by the same type, open brackets are closed in the correct order, and every close bracket has a corresponding open bracket.

Examples

Input: s = "()"

Output: true

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

Output: true

Input: s = "(]"

Output: false

Constraints

  • •1 ≤ s.length ≤ 10⁴
  • •s consists of parentheses only

Your Solution

JavaScript·6 test cases·Max 5,000 chars · 2s timeout · 10 runs/30s
Loading...