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
Python bisect solution, slow but AC

@leetcodedavy said in Python bisect solution, slow but AC:
bisect.insert(position, num)
Did you mean
sortedList.insert(position, num)
? Causebisect
module does not have aninsert()
method. Thanks.