cswork / OA打开练习工作台

DatabricksOA #1

Count Pairs with One Digit Swap

估计中等评测数据准备中,可先阅读题面

考点(AI 标注)哈希计数字符串

You are given an array of integers numbers. Your task is to count the number of distinct pairs of indices (i, j) (where i < j) such that numbers[i] can be obtained from numbers[j] by swapping exactly two digits in their decimal representation. Both numbers must have the same number of digits to be considered.

Example: numbers = [1, 23, 156, 1650, 651, 165, 32] returns 3 (pairs: (23, 32), (156, 651), (156, 165)).

Constraints

1 ≤ numbers.length ≤ 10⁴, 1 ≤ numbers[i] ≤ 10⁹.