import bisect class Solution(object): def countSmaller(self, nums): result =  sortedList =  for num in nums[::-1]: position=bisect.bisect_left(sortedList, num) result.insert(0,position) bisect.insort(sortedList,num) return result
Actually, this logic is great and fast. result.insert takes a lot of time. you can try result.append(position) and then return res[::-1]. you will see your running time will around 170ms which is about half of your current running time.
Also, since you already get the position using bisect_left, you can just call bisect.insert(position, num), rather than bisect.insort(sortedList,num). That would save another log(n) binary search time.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.