Who can tell me Why?


  • 0
    Y

    "public class Solution {
    public List<Integer> countSmaller(int[] nums) {
    if(nums == null || nums.length == 0){
    return new ArrayList<Integer>();
    }
    int len = nums.length - 1;
    List<Integer> list = new ArrayList<Integer>();
    Integer [] record = new Integer[nums.length];
    record[len] = 0;
    list.add(nums[nums.length - 1]);
    for(int i = nums.length -2; i >= 0; i--){
    int index = Collections.binarySearch(list, nums[i]);
    if(index < 0){
    index = -(index + 1);
    }
    list.add(index, nums[i]);
    record[i] = index;
    }
    return Arrays.asList(record);
    }
    if will get wrong answer or time limited
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.