Pharrell C.

asked • 01/18/21

Data Structure Using C

Given a string s containing just the characters '(', ')', '{', '}', '[' 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.


Example 1:

Input: s = "()"

Output: true


Example 2:

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

Output: true


Example 3:

Input: s = "(]"

Output: false


Example 4:

Input: s = "([)]"

Output: false


Example 5:

Input: s = "{[]}"

Output: true

1 Expert Answer

By:

Aaron T. answered • 01/18/21

Tutor
4.8 (45)

Bachelors in Computer Science with 8+ Years of Industry Experience

Pharrell C.

thanks
Report

01/18/21

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.