MCPcopy Index your code
hub / github.com/careercup/ctci / getDistinctSortedArray

Method getDistinctSortedArray

java/Chapter 9/Question9_3/Question.java:37–48  ·  view source on GitHub ↗
(int size)

Source from the content-addressed store, hash-verified

35
36 /* Creates an array that is distinct and sorted */
37 public static int[] getDistinctSortedArray(int size) {
38 int[] array = AssortedMethods.randomArray(size, -1 * size, size);
39 Arrays.sort(array);
40 for (int i = 1; i < array.length; i++) {
41 if (array[i] == array[i-1]) {
42 array[i]++;
43 } else if (array[i] < array[i - 1]) {
44 array[i] = array[i-1] + 1;
45 }
46 }
47 return array;
48 }
49
50 public static void main(String[] args) {
51 for (int i = 0; i < 1000; i++) {

Callers 1

mainMethod · 0.95

Calls 2

randomArrayMethod · 0.95
sortMethod · 0.45

Tested by

no test coverage detected