You are viewing a single comment's thread. Return to all comments →
I think i've figured it out. He's basically doing a swap of
arr[i] and arr[arr[i] - 1]
You can achieve the same using the longer way:
var temp = arr[i]; arr[i] = arr[arr[i]-1] arr[temp - 1] = temp
var temp = arr[i];
arr[i] = arr[arr[i]-1]
arr[temp - 1] = temp
If you know python, you can implement this same code and use a more natural shorthand that python provides
a, b = b, a
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Swaps 2
You are viewing a single comment's thread. Return to all comments →
I think i've figured it out. He's basically doing a swap of
You can achieve the same using the longer way:
If you know python, you can implement this same code and use a more natural shorthand that python provides