I believe you are correct. Instead of using a stack, you can add one for opening, subtract one for closing and as long as your count is non-negative, it will work the same way. Its effectively the same algorithm, except instead of actually keeping the stack, you're keeping track of the number of objects in the stack, and it'll reduce your worst case space requirement from linear in the number of parentheses to logarithmic.