We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ab7d1d3 commit ee5ac49Copy full SHA for ee5ac49
1 file changed
sorts/swap_sort.ts
@@ -21,17 +21,13 @@ export const minSwapsToSort = (inputArr: number[]): number => {
21
for (let i = 0; i < inputArr.length; i++) {
22
if (inputArr[i] !== sortedArray[i]) {
23
const temp = inputArr[i]
24
-
25
inputArr[i] = inputArr[indexMap.get(sortedArray[i])]
26
27
inputArr[indexMap.get(sortedArray[i])] = temp
28
29
indexMap.set(temp,indexMap.get(sortedArray[i]))
30
31
indexMap.set(sortedArray[i],1)
32
33
swaps++
34
}
35
+
36
return swaps
37
-}
+}
0 commit comments