您的位置:首页 > 编程语言 > Python开发

leetcode-5344 有多少小于当前数字的数字 Python

2020-03-15 12:14 966 查看

方法一:

class Solution:
def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]:
return [sum(1 for j in range(len(nums)) if i > nums[j]) for i in nums]

方法二:

class Solution:
def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]:
res = []
count = 0
for i in range(len(nums)):
for j in range(len(nums)):
if nums[i]>nums[j]:
count += 1
res.append(count)
count = 0
return res
  • 点赞
  • 收藏
  • 分享
  • 文章举报
Xenonon 发布了32 篇原创文章 · 获赞 0 · 访问量 292 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: