Share my python solution, easy to understand


  • 0
    F
    class Solution(object):
    def findKthLargest(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: int
        """
        if k>len(nums) or k<=0:
            return None
        rst=nums[:k]
        rst.sort()
        for i in range(k, len(nums)):
            if nums[i]>rst[0]:
                rst.append(nums[i])
                rst.pop(0)
                rst.sort()
        return rst[0]

Log in to reply
 

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