package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits/
 */
public class Problem1356 {
    public int[] sortByBits(int[] arr) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1356 prob = new Problem1356();
        System.out.println(Arrays.toString(prob.sortByBits(new int[]{0,1,2,3,4,5,6,7,8}))); // [0,1,2,4,8,3,5,6,7]
        System.out.println(Arrays.toString(prob.sortByBits(new int[]{1024,512,256,128,64,32,16,8,4,2,1}))); // [1,2,4,8,16,32,64,128,256,512,1024]
        System.out.println(Arrays.toString(prob.sortByBits(new int[]{10000,10000}))); // [10000,10000]
        System.out.println(Arrays.toString(prob.sortByBits(new int[]{2,3,5,7,11,13,17,19}))); // [2,3,5,17,7,11,13,19]
        System.out.println(Arrays.toString(prob.sortByBits(new int[]{10, 100, 1000, 10000}))); // [10,100,10000,1000]
    }
}

@@ -198,736 +198,1041 @@
     
-// TODO%0A        return null
+ValueCount%5B%5D vc = new ValueCount%5Barr.length%5D
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1356 prob = new Problem1356();%0A        System.out.println(Arrays.toString(prob.sortByBits(new int%5B%5D%7B0,1,2,3,4,5,6,7,8%7D))); // %5B0,1,2,4,8,3,5,6,7%5D%0A        System.out.println(Arrays.toString(prob.sortByBits(new int%5B%5D%7B1024,512,256,128,64,32,16,8,4,2,1%7D))); // %5B1,2,4,8,16,32,64,128,256,512,1024%5D%0A        System.out.println(Arrays.toString(prob.sortByBits(new int%5B%5D%7B10000,10000%7D))); // %5B10000,10000%5D%0A        System.out.println(Arrays.toString(prob.sortByBits(new int%5B%5D%7B2,3,5,7,11,13,17,19%7D))); // %5B2,3,5,17,7,11,13,19%5D%0A        System.out.println(Arrays.toString(prob.sortByBits(new int%5B%5D%7B10, 100, 1000, 10000%7D))); // %5B10,100,10000,1000%5D
+for (int i = 0; i %3C arr.length; i++) %7B%0A            vc%5Bi%5D = new ValueCount(arr%5Bi%5D, numOnes(arr%5Bi%5D));%0A        %7D%0A        Arrays.sort(vc, (a, b) -%3E %7B%0A            int cmp = Integer.compare(a.count, b.count);%0A            if (cmp == 0) %7B%0A                return Integer.compare(a.value, b.value);%0A            %7D%0A            return cmp;%0A        %7D);%0A        int%5B%5D answer = new int%5Barr.length%5D;%0A        for (int i = 0; i %3C vc.length; i++) %7B%0A            answer%5Bi%5D = vc%5Bi%5D.value;%0A        %7D%0A        return answer;%0A    %7D%0A%0A    private static class ValueCount %7B%0A        private final int value;%0A        private final int count;%0A%0A        public ValueCount(int value, int count) %7B%0A            this.value = value;%0A            this.count = count;%0A        %7D%0A    %7D%0A%0A    private static int numOnes(int n) %7B%0A        int count = 0;%0A        int num = n;%0A        while (num %3E 0) %7B%0A            if ((num & 1) == 1) %7B%0A                count++;%0A            %7D%0A            num %3E%3E= 1;%0A        %7D%0A        return count;
 %0A   

Solve problem 1356