Sunday, February 14, 2021

Leetcode Everyday: 1365. How Many Numbers Are Smaller Than the Current Number. Easy

public class Solution {
    public int[] SmallerNumbersThanCurrent(int[] nums) {
        var sorted = nums.OrderBy(n => n).ToArray();
        var smallCounts = new List();
        for (var i = 0; i < nums.Length; ++i) {
            var count = Array.IndexOf(sorted, nums[i]);
            smallCounts.Add(count);
        }
        return smallCounts.ToArray();
    }
}
Source: https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/

No comments:

Post a Comment