3265. Count Almost Equal Pairs I Medium
1/**
2 * [3265] Count Almost Equal Pairs I
3 *
4 * You are given an array nums consisting of positive integers.
5 * We call two integers x and y in this problem almost equal if both integers can become equal after performing the following operation at most once:
6 *
7 * Choose either x or y and swap any two digits within the chosen number.
8 *
9 * Return the number of indices i and j in nums where i < j such that nums[i] and nums[j] are almost equal.
10 * Note that it is allowed for an integer to have leading zeros after performing an operation.
11 *
12 * <strong class="example">Example 1:
13 * <div class="example-block">
14 * Input: <span class="example-io">nums = [3,12,30,17,21]</span>
15 * Output: <span class="example-io">2</span>
16 * Explanation:
17 * The almost equal pairs of elements are:
18 *
19 * 3 and 30. By swapping 3 and 0 in 30, you get 3.
20 * 12 and 21. By swapping 1 and 2 in 12, you get 21.
21 * </div>
22 * <strong class="example">Example 2:
23 * <div class="example-block">
24 * Input: <span class="example-io">nums = [1,1,1,1,1]</span>
25 * Output: <span class="example-io">10</span>
26 * Explanation:
27 * Every two elements in the array are almost equal.
28 * </div>
29 * <strong class="example">Example 3:
30 * <div class="example-block">
31 * Input: <span class="example-io">nums = [123,231]</span>
32 * Output: <span class="example-io">0</span>
33 * Explanation:
34 * We cannot swap any two digits of 123 or 231 to reach the other.
35 * </div>
36 *
37 * Constraints:
38 *
39 * 2 <= nums.length <= 100
40 * 1 <= nums[i] <= 10^6
41 *
42 */
43pub struct Solution {}
44
45// problem: https://leetcode.com/problems/count-almost-equal-pairs-i/
46// discuss: https://leetcode.com/problems/count-almost-equal-pairs-i/discuss/?currentPage=1&orderBy=most_votes&query=
47
48// submission codes start here
49
50impl Solution {
51 pub fn count_pairs(nums: Vec<i32>) -> i32 {
52 0
53 }
54}
55
56// submission codes end
57
58#[cfg(test)]
59mod tests {
60 use super::*;
61
62 #[test]
63 fn test_3265() {
64 }
65}
66
Back
© 2025 bowen.ge All Rights Reserved.