파비의 매일매일 공부기록

Today's Challenge 본문

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
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

Today's Challenge  (0) 2022.07.25
Today's Challenge  (0) 2022.07.24
Today's Challenge  (0) 2022.07.22
Today's Challenge  (0) 2022.07.21
Today's Challenge  (0) 2022.07.20
Comments