Skip to content
Advertisement

Parenthesis/Brackets Matching using Stack algorithm

For example if the parenthesis/brackets is matching in the following:

JavaScript

and so on but if the parenthesis/brackets is not matching it should return false, eg:

JavaScript

and so on. Can you please check this code? Thanks in advance.

JavaScript

Advertisement

Answer

Your code has some confusion in its handling of the ‘{‘ and ‘}’ characters. It should be entirely parallel to how you handle ‘(‘ and ‘)’.

This code, modified slightly from yours, seems to work properly:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement