classSolution:deffindKthNumber(self,m,n,k):""" :type m: int :type n: int :type k: int :rtype: int """ nums =[]for i inrange(1, m+1):for j inrange(1, n+1): heapq.heappush(nums, i*j)return heapq.nsmallest(k, nums)[-1]
Heapq [Memory Limit Exceeded]
classSolution:deffindKthNumber(self,m,n,k):""" :type m: int :type n: int :type k: int :rtype: int """ nums =[i*j for i inrange(1, m+1)for j inrange(1, n+1)] heapq.heapify(nums)return heapq.nsmallest(k, nums)[-1]