Does calling the sort() method count as cheat?


  • 0
    C

    Simply sort the array and return k - 1 element. 2 lines AC.

        def findKthLargest(self, nums, k):
            nums.sort(reverse=True)
            return nums[k - 1]
    

  • 0
    R

    @chenwu
    Here it's just a practice, whatever you do will be fine.

    But if you encountered this in an interview, you know what the interviewer expect right?


Log in to reply
 

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