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
文章標籤
全站熱搜
留言列表