Given a string containing only parentheses (, ), {, }, [, and ], determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Write a function isValidParentheses that takes in a string s and returns a boolean value indicating whether the parentheses in s are valid. Example: Input: s = "{[()]}" Output: true Input: s = "{[()]}" Output: false Input: s = "{[(])}" Output: false Input: s = "{[()]}()[]" Output: true Note: The input string will only contain the characters (, ), {, }, [, and ]. An empty string is considered valid.

icon
Related questions
Question

Given a string containing only parentheses (, ), {, }, [, and ], determine if the input string is valid. 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.

Write a function isValidParentheses that takes in a string s and returns a boolean value indicating whether the parentheses in s are valid.

Example: Input: s = "{[()]}" Output: true

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

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

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

Note:

  • The input string will only contain the characters (, ), {, }, [, and ].
  • An empty string is considered valid.
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer