Checking that brackets like {[()]} are balanced needs more than counting, because the order of closing matters. The most recently opened bracket must close first, which is exactly what a stack gives you. Use the same idea for matching tags, checking expressions or removing invalid brackets. If there is only one kind of bracket, a simple counter is enough.