Easy C++ Solution || 100% beat || O(n) complexity
Intuition\nTo determine if a string of digits is "balanced," we can separate the string into digits at even and odd indices. Summing the digits in these two gro
# Intuition\nTo determine if a string of digits is "balanced," we can separate the string into digits at even and odd indices. Summing the digits in these two groups lets us compare the sums to see if they are equal.\n\n# Approach\n1. Initialize two variables, evesum and oddsum, to store the sum of digits at even and odd indices, respectively.\n1. Loop through each character in the string num.\n1. Convert each character to an integer.\n1. If the index is even, add the digit to evesum; if the index is odd, add it to oddsum.\n1. After the loop, check if evesum is equal to oddsum. If they are, return true; otherwise, return false.\n\n# Complexity\n- Time complexity: O(n), where \uD835\uDC5B is the length of num, since we loop through each digit once.\n\n- Space complexity: O(1), as we only use a constant amount of additional space.\n\n# Code\n```cpp []\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n    bool isBalanced(string num) {\n        int evesum = 0, oddsum = 0;\n        \n        for (int i = 0; i < num.size(); i++) {\n            int x = num[i] - \'0\';  \n            \n            if (i % 2 == 0) {     \n                evesum += x;\n            } else {            \n                oddsum += x;\n            }\n        }\n        \n        return evesum == oddsum;\n    }\n};\n\n```
['C++']