2535. Difference Between Element Sum and Digit Sum of an Array Easy

@problem@discussion
#Array#Math



1/**
2 * [2535] Difference Between Element Sum and Digit Sum of an Array
3 *
4 * You are given a positive integer array nums.
5 * 
6 * 	The element sum is the sum of all the elements in nums.
7 * 	The digit sum is the sum of all the digits (not necessarily distinct) that appear in nums.
8 * 
9 * Return the absolute difference between the element sum and digit sum of nums.
10 * Note that the absolute difference between two integers x and y is defined as |x - y|.
11 *  
12 * <strong class="example">Example 1:
13 * 
14 * Input: nums = [1,15,6,3]
15 * Output: 9
16 * Explanation: 
17 * The element sum of nums is 1 + 15 + 6 + 3 = 25.
18 * The digit sum of nums is 1 + 1 + 5 + 6 + 3 = 16.
19 * The absolute difference between the element sum and digit sum is |25 - 16| = 9.
20 * 
21 * <strong class="example">Example 2:
22 * 
23 * Input: nums = [1,2,3,4]
24 * Output: 0
25 * Explanation:
26 * The element sum of nums is 1 + 2 + 3 + 4 = 10.
27 * The digit sum of nums is 1 + 2 + 3 + 4 = 10.
28 * The absolute difference between the element sum and digit sum is |10 - 10| = 0.
29 * 
30 *  
31 * Constraints:
32 * 
33 * 	1 <= nums.length <= 2000
34 * 	1 <= nums[i] <= 2000
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array/
40// discuss: https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn difference_of_sum(nums: Vec<i32>) -> i32 {
46        0
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_2535() {
58    }
59}
60


Back
© 2025 bowen.ge All Rights Reserved.