Skip to content

Latest commit

 

History

History
25 lines (22 loc) · 617 Bytes

1985.md

File metadata and controls

25 lines (22 loc) · 617 Bytes

1985. Find the Kth Largest Integer in the Array

Solution 1 (time O(nlog(n)), space O(1))

class Solution(object):
    def kthLargestNumber(self, nums, k):
        """
        :type nums: List[str]
        :type k: int
        :rtype: str
        """
        def compare(a, b):
            if len(a) > len(b):
                return -1
            if len(a) < len(b):
                return 1
            if a > b:
                return -1
            else:
                return 1
        
        nums.sort(key=functools.cmp_to_key(compare))
        return nums[k - 1]