Class Solution
-
- All Implemented Interfaces:
public final class Solution3340 - Check Balanced String.
Easy
You are given a string
numconsisting of only digits. A string of digits is called balanced if the sum of the digits at even indices is equal to the sum of digits at odd indices.Return
trueifnumis balanced , otherwise returnfalse.Example 1:
Input: num = "1234"
Output: false
Explanation:
The sum of digits at even indices is
1 + 3 == 4, and the sum of digits at odd indices is2 + 4 == 6.Since 4 is not equal to 6,
numis not balanced.
Example 2:
Input: num = "24123"
Output: true
Explanation:
The sum of digits at even indices is
2 + 1 + 3 == 6, and the sum of digits at odd indices is4 + 2 == 6.Since both are equal the
numis balanced.
Constraints:
2 <= num.length <= 100numconsists of digits only
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final BooleanisBalanced(String num)-
-
Method Detail
-
isBalanced
final Boolean isBalanced(String num)
-
-
-
-