BEATING 99% IN 1ms EASY JAVA CODE
ApproachTo solve this problem efficiently, we can break it down into the following steps:
Initialization:
We need to keep track of the sums of digits at even an
# Approach
<!-- Describe your approach to solving the problem. -->
To solve this problem efficiently, we can break it down into the following steps:

1. Initialization:
We need to keep track of the sums of digits at even and odd indices. We can initialize two variables: s1 (for odd indices) and s2 (for even indices).
We also need to know the length of the string num in order to loop over its characters.
2. Iterate Over the String:
For each character in the string, we need to check its index:
If the index is even (i.e., i % 2 == 0), add the value of the character (converted to an integer) to s2.
If the index is odd (i.e., i % 2 == 1), add the value of the character (converted to an integer) to s1.
3. Final Comparison:
After the loop, compare the sums:
If the sum of digits at even indices (s2) is equal to the sum of digits at odd indices (s1), return true (indicating that the string is balanced).
Otherwise, return false.
# Complexity
- Time complexity: O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public boolean isBalanced(String num) {
        int s1=0,s2=0,n=num.length();
        for(int i=0;i<n;i++){
            if(i%2==0){
                s2+=num.charAt(i) - '0';
            }else{
                s1+=num.charAt(i) - '0';
            }
        }
        if(s1==s2){
            return true;
        }    
        return false;
    }
}
```
['Java']