Easy and simple solution || Beats 100% || String || c++ || Python
C++\ncpp\nclass Solution {\npublic:\n    bool isBalanced(string num) {\n        int odd = 0;\n        int even = 0;\n        for (int i = 0; i < num.size(); i++
### C++\n```cpp\nclass Solution {\npublic:\n    bool isBalanced(string num) {\n        int odd = 0;\n        int even = 0;\n        for (int i = 0; i < num.size(); i++) {\n            int digit = num[i] - \'0\';\n            if (i % 2)\n                odd += digit;\n            else\n                even += digit;\n        }\n        return even == odd;\n    }\n};\n```\n### Python\n\n```python\nclass Solution:\n    def isBalanced(self, num: str) -> bool:\n        odd = 0\n        even = 0\n        for i in range(len(num)):\n            digit = int(num[i])\n            if i % 2 == 0:\n                even += digit\n            else:\n                odd += digit\n        return even == odd\n```\n# Beats 100%\n\n![image.png](https://assets.leetcode.com/users/images/e6a87c25-adb6-40d9-b2db-d69b9c0a0f5e_1730607990.9420562.png)\n\n\n### Explanation\n\n- **Intuition**: To check if the sum of digits at even positions equals the sum of digits at odd positions.\n\n- **Approach**:\n  1. Initialize `odd` and `even` as 0 to store sums of digits at odd and even indices, respectively.\n  2. Loop through each digit in the string:\n     - Add the digit to `even` if its index is even, otherwise to `odd`.\n  3. Return `True` if `even` and `odd` sums are equal; otherwise, `False`.\n\n### Complexity\n\n- **Time Complexity**: \\(O(n)\\) since we traverse each digit in `num` once.\n- **Space Complexity**: \\(O(1)\\), as we use only two variables to hold the sums.
['String', 'Python', 'C++', 'Python3']