m.khooryani's blog

By m.khooryani, history, 6 years ago, In English
        int limit = 1 << n;
        for (int i = 0; i < limit; i++) {
            if (Integer.bitCount(i) >= 3) {
                System.out.println(i);
            }
        }
 
 
 
 
  • Vote: I like it
  • +3
  • Vote: I do not like it

»
6 years ago, # |
  Vote: I like it +27 Vote: I do not like it

There's technically no asymptotically better way. Note that the number of integers in that range that have bitCount < 3 is So the total number of integers you would be printing out is O(2n) - O(n2) = O(2n),  which is at least necessary asymptotically.