Given the input inStr, give the boolean output out indicating whether all the parentheses are balanced.
Examples:
The string may include characters other than ( and ), but you should ignore them.
Incidentally, this problem was inspired from the Rosetta Code site. Why not create a few problems of your own by poking around the tasks at Rosetta Code?
can be solved without 'regexp'
A slightly more robust test might include a balanced equation starting with something other than an opening bracket.
Test 3 might be
inStr = '3*(z*(a-(x+3))/(y))';
Wrong solution.
it doesn't work in some cases not included in test suite. for example:
inStr = '(z*(a-(x+3))/(y)*z)';
Nice solution
Seems to fail for inStr='(' , '((', etc.
I admit this is cheating, but I think it also stresses the need for more tests in the suite. Also, not all the cases should necessarily be visible, so you can't adapt a solution like this.
This solution fails for the input ')()', i.e. it returns true when it should return false.
This solution fails for the input '(()', i.e. it returns true when it should return false.
This solution fails for the input '(()', i.e. it returns true when it should return false.
This entry is incorrect. It fails the simple case of:
isBalanced('(')
The Hitchhiker's Guide to MATLAB
2725 Solvers
Who knows the last digit of pi?
495 Solvers
302 Solvers
Find out missing number from a vector of 9 elements
208 Solvers
511 Solvers