Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Quick Question

Name: Anonymous 2009-11-03 2:36


public class MostOftenOccurring{
  public static int occursMostOften(int[] a){
    int[] b = new int[a.length];
    for (int i = 0; i < a.length; i++){
      b[i] = CountOccurrences.countOccurrences(a, a[i]);
    }
    for (int j = 0; j < b.length; j++){
      if (Maximum.maximum(b) == b[j]){
        return b[j];
      }
    }
    return 666; //I did this to make the compiler happy
  }
  public static void main(String[] args){
    int[] testArray = {1};
    System.out.println(occursMostOften(testArray));
  }
}



Is there any way that return 666; could ever be executed?

Name: Anonymous 2009-11-03 3:33

There are a number of ways, for example if a is empty. You are retarded anyway. You do not need an O(n2) time and O(n) space method to find the most common element in an array. It can be done in linear time with constant space.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List