package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * https://leetcode.com/problems/count-of-smaller-numbers-after-self/
 */
public class Problem315 {
    public List<Integer> countSmaller(int[] nums) {
        List<Integer> result = new ArrayList<>();
        // TODO:
        return result;
    }

    public static void main(String[] args) {
        Problem315 prob = new Problem315();
        System.out.println(prob.countSmaller(new int[]{5, 2, 6, 1})); // [2, 1, 1, 0]
    }
}

@@ -34,20 +34,17 @@
 il.Array
-List
+s
 ;%0Aimport
@@ -229,271 +229,756 @@
     
-List%3CInteger%3E result = new ArrayList%3C%3E();%0A        // TODO:%0A        return result;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem315 prob = new Problem315();%0A        System.out.println(prob.countSmaller(new int%5B%5D%7B5, 2, 6, 1%7D)); // %5B2, 1, 1, 0%5D
+int%5B%5D tmp = nums.clone();%0A        Arrays.sort(tmp);%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A            nums%5Bi%5D = Arrays.binarySearch(tmp, nums%5Bi%5D) + 1;%0A        %7D%0A        int%5B%5D bit = new int%5Bnums.length + 1%5D;%0A        Integer%5B%5D ans = new Integer%5Bnums.length%5D;%0A        for (int i = nums.length - 1; i %3E= 0; i--) %7B%0A            ans%5Bi%5D = query(bit, nums%5Bi%5D - 1);%0A            add(bit, nums%5Bi%5D, 1);%0A        %7D%0A        return Arrays.asList(ans);%0A    %7D%0A%0A    private void add(int%5B%5D bit, int i, int val) %7B%0A        for (; i %3C bit.length; i += i & -i) %7B%0A            bit%5Bi%5D += val;%0A        %7D%0A    %7D%0A%0A    private int query(int%5B%5D bit, int i) %7B%0A        int ans = 0;%0A        for (; i %3E 0; i -= i & -i) %7B%0A            ans += bit%5Bi%5D;%0A        %7D%0A        return ans;
 %0A   

Put solution for problem 315