You are viewing a single comment's thread. Return to all comments →
My solution in java:
static int minimumSwaps(int[] arr) { int minimumSwaps = 0; for (int i = 0; i < arr.length; i++) { int current = arr[i]; while(current != i + 1){ int temp = arr[current - 1]; arr[current - 1] = current; arr[i] = temp; ++minimumSwaps; current = temp; } } return minimumSwaps; }
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 →
My solution in java: