package leetcode;

/**
 * https://leetcode.com/problems/kth-largest-element-in-an-array/
 */
public class Problem215 {
    public int findKthLargest(int[] nums, int k) {
        
    }
    
    public static void main(String[] args) {
        Problem215 prob = new Problem215();
        System.out.println(prob.findKthLargest(new int[]{2, 7, 4, 5, 6, 3, 1}, 4));
    }
}

@@ -167,24 +167,154 @@
 ) %7B%0A        
+IntRef result = new IntRef();%0A        findKthLargest(nums, nums.length-k, 0, nums.length-1, result);%0A        return result.result;
 %0A    %7D%0A    %0A
@@ -322,21 +322,22 @@
    p
-ublic
+rivate
  static 
 void
@@ -336,161 +336,1162 @@
 tic 
-void main(String%5B%5D args) %7B%0A        Problem215 prob = new Problem215();%0A        System.out.println(prob.findKthLargest(new int%5B%5D%7B2, 7, 4, 5, 6, 3, 1%7D, 4))
+class IntRef %7B%0A        int result;%0A    %7D%0A    %0A    private void findKthLargest(int%5B%5D nums, int k, int left, int right, IntRef result) %7B%0A        if (left %3E right) %7B%0A            return;%0A        %7D%0A        int p = partition(nums, left, right);%0A        if (p == k) %7B%0A            result.result = nums%5Bp%5D;%0A        %7D%0A        findKthLargest(nums, k, left, p-1, result);%0A        findKthLargest(nums, k, p+1, right, result);%0A    %7D%0A    %0A    private int partition(int%5B%5D nums, int left, int right) %7B%0A        int originalLeft = left;%0A        int originalRight = right;%0A        int p = nums%5BoriginalLeft%5D;%0A        while (true) %7B%0A            while (left %3C originalRight && nums%5Bleft%5D %3C= p) %7B%0A                left++;%0A            %7D%0A            while (right %3E originalLeft && nums%5Bright%5D %3E= p) %7B%0A                right--;%0A            %7D%0A            if (left %3C right) %7B%0A                swap(nums, left, right);%0A            %7D else %7B%0A                break;%0A            %7D%0A        %7D%0A        swap(nums, originalLeft, right);%0A        return right;%0A    %7D%0A    %0A    private void swap(int%5B%5D nums, int i, int j) %7B%0A        int tmp = nums%5Bi%5D;%0A        nums%5Bi%5D = nums%5Bj%5D;%0A        nums%5Bj%5D = tmp
 ;%0A  

Solve problem 215