You are viewing a single comment's thread. Return to all comments →
hmm, I used passing an array convert to List also got timeout
public static double findMedian(int[] array){ double median = 0; List<Integer> list = new ArrayList<Integer>(); int i = 0; while(i < array.length){ if(array[i] != 0) list.add(array[i]); i++; } Collections.sort(list); Collections.reverse(list); //System.out.println(Arrays.toString(array)); //System.out.println(list.toString()); if(list.size() % 2 == 1){ median = list.get(Math.abs(list.size()/2)); }else{ median = (list.get(list.size()/2 - 1) + list.get(list.size()/2)) / 2.0; } return median; }
Seems like cookies are disabled on this browser, please enable them to open this website
Heaps: Find the Running Median
You are viewing a single comment's thread. Return to all comments →
hmm, I used passing an array convert to List also got timeout