Selection sort concept


  • 0
    R

    class Solution(object):

    def findKthLargest(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: int
        """
        if len(nums) == 1:
            return nums[0]
        for i in range(0, k):
            max_num = None
            for j in range(i, len(nums)):
                if max_num is None:
                    max_num = nums[j]
                if nums[j] > max_num:
                    max_num = nums[j]
                    nums[j], nums[i] = nums[i], nums[j]
        return nums[k-1]

Log in to reply
 

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