2544. Alternating Digit Sum Easy

@problem@discussion
#Math



1/**
2 * [2544] Alternating Digit Sum
3 *
4 * You are given a positive integer n. Each digit of n has a sign according to the following rules:
5 * 
6 * 	The most significant digit is assigned a positive sign.
7 * 	Each other digit has an opposite sign to its adjacent digits.
8 * 
9 * Return the sum of all digits with their corresponding sign.
10 *  
11 * <strong class="example">Example 1:
12 * 
13 * Input: n = 521
14 * Output: 4
15 * Explanation: (+5) + (-2) + (+1) = 4.
16 * 
17 * <strong class="example">Example 2:
18 * 
19 * Input: n = 111
20 * Output: 1
21 * Explanation: (+1) + (-1) + (+1) = 1.
22 * 
23 * <strong class="example">Example 3:
24 * 
25 * Input: n = 886996
26 * Output: 0
27 * Explanation: (+8) + (-8) + (+6) + (-9) + (+9) + (-6) = 0.
28 * 
29 *  
30 * Constraints:
31 * 
32 * 	1 <= n <= 10^9
33 * 
34 *  
35 * <style type="text/css">.spoilerbutton {display:block; border:dashed; padding: 0px 0px; margin:10px 0px; font-size:150%; font-weight: bold; color:#000000; background-color:cyan; outline:0; 
36 * }
37 * .spoiler {overflow:hidden;}
38 * .spoiler > div {-webkit-transition: all 0s ease;-moz-transition: margin 0s ease;-o-transition: all 0s ease;transition: margin 0s ease;}
39 * .spoilerbutton[value="Show Message"] + .spoiler > div {margin-top:-500%;}
40 * .spoilerbutton[value="Hide Message"] + .spoiler {padding:5px;}
41 * </style>
42 * 
43 */
44pub struct Solution {}
45
46// problem: https://leetcode.com/problems/alternating-digit-sum/
47// discuss: https://leetcode.com/problems/alternating-digit-sum/discuss/?currentPage=1&orderBy=most_votes&query=
48
49// submission codes start here
50
51impl Solution {
52    pub fn alternate_digit_sum(n: i32) -> i32 {
53        0
54    }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61    use super::*;
62
63    #[test]
64    fn test_2544() {
65    }
66}
67


Back
© 2025 bowen.ge All Rights Reserved.