From f91b9446f982eef49fc2f45d82142f392c94af95 Mon Sep 17 00:00:00 2001 From: Nahom Garefo <119704083+Blacknahil@users.noreply.github.com> Date: Fri, 29 Dec 2023 17:22:37 +0300 Subject: [PATCH] Added solution for How Many Numbers Are Smaller Than the Current Number --- ...ny-numbers-are-smaller-than-the-current-number.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 week4/how-many-numbers-are-smaller-than-the-current-number.py diff --git a/week4/how-many-numbers-are-smaller-than-the-current-number.py b/week4/how-many-numbers-are-smaller-than-the-current-number.py new file mode 100644 index 0000000..e2ed6b0 --- /dev/null +++ b/week4/how-many-numbers-are-smaller-than-the-current-number.py @@ -0,0 +1,12 @@ +class Solution: + def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]: + sorted_nums=sorted(nums) + dic={} + for i,num in enumerate(sorted_nums): + if not num in dic: + dic[num]=i + ans=[] + for num in nums: + ans.append(dic[num]) + return ans + \ No newline at end of file