You are viewing a single comment's thread. Return to all comments →
static int runningTime(int[] a) { int i, j, key, shifts = 0; for (j = 1; j < a.length; j++) { key = a[j]; i = j-1; while (i >= 0 && a[i] > key) { a[i+1] = a[i]; i = i-1; shifts++; } a[i+1] = key; } return shifts; }
Here is my code. It passes all the testcases but few of them take too much time. Is it because of O(N^2) time complexity?
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 →
Here is my code. It passes all the testcases but few of them take too much time. Is it because of O(N^2) time complexity?