leetcode在力扣 App 中打开
调试中...
调试中...
题目描述
题目描述
题解
题解
提交记录
提交记录
代码
代码
测试用例
测试用例
测试结果
测试结果
中等
相关标签
相关企业
提示

你有一个数组 nums ,它只包含  整数,所有正整数的数位长度都 相同 。

两个整数的 数位差 指的是两个整数 相同 位置上不同数字的数目。

请你返回 nums 中 所有 整数对里,数位差之和。

 

示例 1:

输入:nums = [13,23,12]

输出:4

解释:
计算过程如下:
13 和 23 的数位差为 1 。
- 13 和 12 的数位差为 1 。
23 和 12 的数位差为 2 。
所以所有整数数对的数位差之和为 1 + 1 + 2 = 4 。

示例 2:

输入:nums = [10,10,10,10]

输出:0

解释:
数组中所有整数都相同,所以所有整数数对的数位不同之和为 0 。

 

提示:

  • 2 <= nums.length <= 105
  • 1 <= nums[i] < 109
  • nums 中的整数都有相同的数位长度。
通过次数
21.6K
提交次数
39.8K
通过率
54.3%


相关企业

提示 1
You can solve the problem for digits that are on the same position separately, and then sum up all the answers.

提示 2
For each position, count the number of occurences of each digit from 0 to 9 that appear on that position.

提示 3
Let c be the number of occurences of a digit on a position, that will contribute with c * (n - c) to the final answer, where n is the number of integers in nums.

相似题目

评论 (0)

贡献者
© 2025 领扣网络(上海)有限公司
0 人在线
行 1,列 1
nums =
[13,23,12]
Source