English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2 answers

This is a typical intro to CS assignment which has many solutions online... Most often solved via a "stack" implementation.

See source(s) below for reference to some solutions.

PS: Ivanhoe... Your solution will not work... What about "))((" ?
Your method only tests if equal number of left & right... Does not test for legal nesting!

2006-07-01 01:13:37 · answer #1 · answered by N2FC 6 · 0 0

create a counter, set it to 0 and loop through the string to be checked
every time ( occurs add 1 to the counter
every time ) occurs subtract 1 from the counter
at the end of the string check if the counter is 0
if not then the brackets dont match

2006-07-01 01:11:07 · answer #2 · answered by Ivanhoe Fats 6 · 0 0

fedest.com, questions and answers