Problem Solving/LeetCode
Today's Challenge
fabichoi
2022. 7. 23. 23:45
https://leetcode.com/problems/count-of-smaller-numbers-after-self/
Count of Smaller Numbers After Self - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
SortedList라는게 있는지 처음 알게 됨.
정렬해서 index를 비교하는 로직이 정답과 무슨 관계인지 잘 모르겠음 =_=
from sortedcontainers import SortedList
class Solution:
def countSmaller(self, nums: List[int]) -> List[int]:
res = []
sorted_nums = SortedList(nums)
for e in nums:
idx = sorted_nums.index(e)
res.append(idx)
sorted_nums.remove(e)
return res
반응형