package leetcode;

/**
 * https://leetcode.com/problems/height-checker/
 */
public class Problem1051 {
    public int heightChecker(int[] heights) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1051 prob = new Problem1051();
        System.out.println(prob.heightChecker(new int[]{1, 1, 4, 2, 1, 3})); // 3
        System.out.println(prob.heightChecker(new int[]{1, 1, 4, 2, 3, 1})); // 2
        System.out.println(prob.heightChecker(new int[]{1, 1, 2, 2, 3, 1})); // 3
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -180,377 +180,287 @@
     
-// TODO%0A        return 0
+int%5B%5D unsorted = Arrays.copyOf(heights, heights.length)
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1051 prob = new Problem1051();%0A        System.out.println(prob.heightChecker(new int%5B%5D%7B1, 1, 4, 2, 1, 3%7D)); // 3%0A        System.out.println(prob.heightChecker(new int%5B%5D%7B1, 1, 4, 2, 3, 1%7D)); // 2%0A        System.out.println(prob.heightChecker(new int%5B%5D%7B1, 1, 2, 2, 3, 1%7D)); // 3
+Arrays.sort(heights);%0A        int answer = 0;%0A        for (int i = 0; i %3C heights.length; i++) %7B%0A            if (heights%5Bi%5D != unsorted%5Bi%5D) %7B%0A                answer++;%0A            %7D%0A        %7D%0A        return answer;
 %0A   

Solve problem 1051