1365. How many number less than the current number

To give you an array nums, all figures for the number of each element nums [i], you count the array smaller than it therein.

In other words, for each nums [i] You must calculate the effective number of j, where j satisfies j! = I and nums [j] <nums [i].

The answer is returned in an array.

prompt:

  • 2 <= nums.length <= 500
  • 0 <= nums[i] <= 100
    class Solution {
        public int[] smallerNumbersThanCurrent(int[] nums) {
            int [] a = new int [nums.length];
            for(int i = 0; i < nums.length; i++)
            {
                for(int j = 0; j < nums.length; j++)
                {
                    if(i != j)
                    {
                        if(nums[i] > nums[j])
                        {
                            a[i] = a[i] + 1;
                        }
                    }
                }
            }
            return a;
        }
    }
    

      

Guess you like

Origin www.cnblogs.com/Duancf/p/12404151.html