You are viewing a single comment's thread. Return to all comments →
This is my Java 8 solution reused the previous challenge method. Feel free to ask me any questions.
public static int runningTime(List<Integer> arr) { int n = arr.size(); int shifts = 0; for(int i = 1; i < n; i++) { int value = arr.get(i); int pos = i - 1; while(pos >= 0 && value < arr.get(pos)) { arr.set(pos + 1, arr.get(pos)); pos--; shifts++; } arr.set(pos + 1, value); } return shifts; }
Seems like cookies are disabled on this browser, please enable them to open this website
Running Time of Algorithms
You are viewing a single comment's thread. Return to all comments →
This is my Java 8 solution reused the previous challenge method. Feel free to ask me any questions.