How would you check if the ends of a chemical formula are balanced from a simplified version of a LeetCode problem, without considering parentheses?