From 422dd1bcc1a3cd8ec38abdf00054894e556e2246 Mon Sep 17 00:00:00 2001 From: ironartisan Date: Mon, 9 Aug 2021 22:07:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A01365.=E6=9C=89=E5=A4=9A?= =?UTF-8?q?=E5=B0=91=E5=B0=8F=E4=BA=8E=E5=BD=93=E5=89=8D=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E5=AD=97python3=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1365.有多少小于当前数字的数字.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/problems/1365.有多少小于当前数字的数字.md b/problems/1365.有多少小于当前数字的数字.md index 6324329c..30241c9b 100644 --- a/problems/1365.有多少小于当前数字的数字.md +++ b/problems/1365.有多少小于当前数字的数字.md @@ -139,7 +139,19 @@ public int[] smallerNumbersThanCurrent(int[] nums) { ``` Python: - +```python +class Solution: + def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]: + res = nums[:] + hash = dict() + res.sort() # 从小到大排序之后,元素下标就是小于当前数字的数字 + for i, num in enumerate(res): + if num not in hash.keys(): # 遇到了相同的数字,那么不需要更新该 number 的情况 + hash[num] = i + for i, num in enumerate(nums): + res[i] = hash[num] + return res +``` Go: JavaScript: