TLE for the last test case.


  • 0
    R

    I am using recursion to solve this problem. Basically, I am checking if any element is less than the pivot element (like which we do in quick sort), if the element is greater than the remaining elements I push them into a temp array and get the length of the temp array and push it to my result.

    Unfortunately, I am getting TLE for the last test case. Can anyone tell me how to speedup this process.

    class Solution(object):
        def countSmaller(self, nums):
            """
            :type nums: List[int]
            :rtype: List[int]
            """
            res = []
            return self.get_lower(nums, res)
            
            
        def get_lower(self, arr, res):
            tmp = []
            if len(arr) is 0:
                return res
            pivot = arr[0]
            for i in range(len(arr)):
                 if arr[i] < pivot:
                    tmp.append(arr[i])
            res.append(len(tmp))
            return self.get_lower(arr[1:], res)
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.