3340. Check Balanced String Easy
1/**
2 * [3340] Check Balanced String
3 *
4 * You are given a string num consisting 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.
5 * Return true if num is balanced, otherwise return false.
6 *
7 * <strong class="example">Example 1:
8 * <div class="example-block">
9 * Input: num<span class="example-io"> = "1234"</span>
10 * Output: <span class="example-io">false</span>
11 * Explanation:
12 *
13 * The sum of digits at even indices is 1 + 3 == 4, and the sum of digits at odd indices is 2 + 4 == 6.
14 * Since 4 is not equal to 6, num is not balanced.
15 * </div>
16 * <strong class="example">Example 2:
17 * <div class="example-block">
18 * Input: num<span class="example-io"> = "24123"</span>
19 * Output: true
20 * Explanation:
21 *
22 * The sum of digits at even indices is 2 + 1 + 3 == 6, and the sum of digits at odd indices is 4 + 2 == 6.
23 * Since both are equal the num is balanced.
24 * </div>
25 *
26 * Constraints:
27 *
28 * 2 <= num.length <= 100
29 * <font face="monospace">num</font> consists of digits only
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/check-balanced-string/
35// discuss: https://leetcode.com/problems/check-balanced-string/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn is_balanced(num: String) -> bool {
41 false
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_3340() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.