Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 15th, 2012  |  syntax: None  |  size: 0.70 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. A tool for calculating the big-O time complexity of Java code?
  2. int dcount = 24423567;
  3.         int a = 0;
  4.         if (dcount == 0){
  5.             a = 1;
  6.         }
  7.  
  8.         String ds = Integer.toString(dcount);
  9.         String[] sa = ds.split("(?<=.)");
  10.         HashSet hs = new HashSet();
  11.         Collections.addAll(hs, sa);
  12.         a = hs.size();
  13.         if (dcount < 0)
  14.             a--;
  15.  
  16.         System.out.println(a);
  17.        
  18. int distinctDigits(int num) {
  19.   if (num == 0) {
  20.     return 1;
  21.   }
  22.  
  23.   boolean[] digits = new boolean[10];
  24.  
  25.   while (num > 0) {
  26.     digits[num % 10] = true;
  27.     num /= 10;
  28.   }
  29.  
  30.   int count = 0;
  31.   for (boolean digit : digits) {
  32.     if (digit) {
  33.       count++;
  34.     }
  35.   }
  36.  
  37.   return count;
  38. }