Valid Parentheses - aloalgo

Valid Parentheses

Easy

You are given a string s.

Your task is to determine if the input string s is valid.

Note that:

  • The string s contains only the characters: '(', ')', '{', '}', '[' and ']'.
  • An opening bracket ('(', '{', or '[') must be closed by the same type of closing bracket.
  • Opening brackets must be closed in the correct order. For example, ([)] is not valid because the [ is closed before the (.
  • Every closing bracket must have a corresponding opening bracket of the same type.

Return true if s is valid, otherwise return false.

Example 1

Input
"[]"
Output
True
Explanation:

The parentheses are correctly matched and ordered.

Example 2

Input
"[{}]()"
Output
True
Explanation:

The parentheses are correctly matched and ordered, even with nested brackets.

Example 3

Input
"(]"
Output
False
Explanation:

The opening bracket '(' is incorrectly closed by ']'.

Example 4

Input
"([)]"
Output
False
Explanation:

The brackets are not closed in the correct order.

Loading...
Input
"[]"
Output
True

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!