close

Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it. That is, for each nums[i] you have to count the number of valid j's such that j != i and nums[j] < nums[i].

Return the answer in an array.

 

解題:

class Solution:
    def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]:
        numsl=len(nums)
        vec,nump=[0]*numsl,[0]*101
        for i in nums:
            nump[i]+=1
        for i in range(1,101):
            nump[i]+=nump[i-1]
        for i in nums:
            for i in range(numsl):
                if nums[i]:
                    vec[i] = nump[nums[i]-1]
        return vec

arrow
arrow
    文章標籤
    leetcode python
    全站熱搜
    創作者介紹
    創作者 低階ㄇㄋ 的頭像
    低階ㄇㄋ

    蟲匯聚之所

    低階ㄇㄋ 發表在 痞客邦 留言(0) 人氣()