mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
42 lines
1.8 KiB
HTML
42 lines
1.8 KiB
HTML
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers where all integers have the <strong>same</strong> number of digits.</p>
|
|
|
|
<p>The <strong>digit difference</strong> between two integers is the <em>count</em> of different digits that are in the <strong>same</strong> position in the two integers.</p>
|
|
|
|
<p>Return the <strong>sum</strong> of the <strong>digit differences</strong> between <strong>all</strong> pairs of integers in <code>nums</code>.</p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">nums = [13,23,12]</span></p>
|
|
|
|
<p><strong>Output:</strong> 4</p>
|
|
|
|
<p><strong>Explanation:</strong><br />
|
|
We have the following:<br />
|
|
- The digit difference between <strong>1</strong>3 and <strong>2</strong>3 is 1.<br />
|
|
- The digit difference between 1<strong>3</strong> and 1<strong>2</strong> is 1.<br />
|
|
- The digit difference between <strong>23</strong> and <strong>12</strong> is 2.<br />
|
|
So the total sum of digit differences between all pairs of integers is <code>1 + 1 + 2 = 4</code>.</p>
|
|
</div>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">nums = [10,10,10,10]</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
|
|
|
<p><strong>Explanation:</strong><br />
|
|
All the integers in the array are the same. So the total sum of digit differences between all pairs of integers will be 0.</p>
|
|
</div>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>2 <= nums.length <= 10<sup>5</sup></code></li>
|
|
<li><code>1 <= nums[i] < 10<sup>9</sup></code></li>
|
|
<li>All integers in <code>nums</code> have the same number of digits.</li>
|
|
</ul>
|