Skip to content

Commit 8d648f7

Browse files
authored
Update 1722-minimize-hamming-distance-after-swap-operations.js
1 parent 1e32fbc commit 8d648f7

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

1722-minimize-hamming-distance-after-swap-operations.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,28 @@ class UnionFind {
3636
* @return {number}
3737
*/
3838
const minimumHammingDistance = function (source, target, allowedSwaps) {
39-
let n = target.length
40-
const u = new UnionFind(n)
39+
const n = target.length
40+
const uf = new UnionFind(n)
4141
for (let A of allowedSwaps) {
42-
let i = A[0],
42+
const i = A[0],
4343
j = A[1]
44-
u.union(i, j)
44+
uf.union(i, j)
4545
}
4646
const M = {}
4747
for (let i = 0; i < n; i++) {
48-
let j = u.find(i)
48+
const j = uf.find(i)
4949
if (M[j] == null) M[j] = {}
5050
if (M[j][source[i]] == null) M[j][source[i]] = 0
5151
M[j][source[i]]++
5252
}
53-
let rest = 0
53+
let res = 0
5454
for (let i = 0; i < n; i++) {
55-
let j = u.find(i)
55+
const j = uf.find(i)
5656
if (M[j][target[i]]) {
5757
if (!--M[j][target[i]]) {
5858
delete M[j][target[i]]
5959
}
60-
} else rest++
60+
} else res++
6161
}
62-
return rest
62+
return res
6363
}

0 commit comments

Comments
 (0)