Java solution,using sort function


  • 0
    L

    public class Solution {
    public int findKthLargest(int[] nums, int k) {
    List<Integer> list = new ArrayList<Integer>();
    for(int i=0;i<nums.length;i++){
    list.add(nums[i]);
    }
    list.sort(null);
    return list.get(nums.length-k);

    }
    

    }


  • 0
    Y

    Why create another ArrayList when you can just run Arrays.sort(nums)?


  • 0
    L

    you are right,I'm new guy,lol


Log in to reply
 

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