I started learning some Mips Assembly development and I encountered in the following question, which I found hard to solve:
A string which is recieved from the user consists only from Brackets, left and right.
A legal string is one that for each left bracket has a closing right bracket.
A bracket can be inside another bracket, as long as it has a closing bracket.
The following "strings" are legal:
(), (()), ((()))
The following "strings" are not legal:
())), (, ((((()
An empty string is also legal.
It is very clear to me that the number of right and left brackets has to be equal.
If I had to do it in Java, I would start "counting" the left brackets, until I reach a right bracket, and then check if the numbers match.
However, I don't know how to it on Mips.
EDIT: see answer below.