3153. Sum of Digit Differences of All Pairs Medium
1/**
2 * [3153] Sum of Digit Differences of All Pairs
3 *
4 * You are given an array nums consisting of positive integers where all integers have the same number of digits.
5 * The digit difference between two integers is the count of different digits that are in the same position in the two integers.
6 * Return the sum of the digit differences between all pairs of integers in nums.
7 *
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">nums = [13,23,12]</span>
11 * Output: 4
12 * Explanation:<br />
13 * We have the following:<br />
14 * - The digit difference between 13 and 23 is 1.<br />
15 * - The digit difference between 13 and 12 is 1.<br />
16 * - The digit difference between 23 and 12 is 2.<br />
17 * So the total sum of digit differences between all pairs of integers is 1 + 1 + 2 = 4.
18 * </div>
19 * <strong class="example">Example 2:
20 * <div class="example-block">
21 * Input: <span class="example-io">nums = [10,10,10,10]</span>
22 * Output: <span class="example-io">0</span>
23 * Explanation:<br />
24 * All the integers in the array are the same. So the total sum of digit differences between all pairs of integers will be 0.
25 * </div>
26 *
27 * Constraints:
28 *
29 * 2 <= nums.length <= 10^5
30 * 1 <= nums[i] < 10^9
31 * All integers in nums have the same number of digits.
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/sum-of-digit-differences-of-all-pairs/
37// discuss: https://leetcode.com/problems/sum-of-digit-differences-of-all-pairs/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn sum_digit_differences(nums: Vec<i32>) -> i64 {
43
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_3153() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.