Skip to content

Latest commit

 

History

History
24 lines (20 loc) · 553 Bytes

Question_1051.md

File metadata and controls

24 lines (20 loc) · 553 Bytes

LeetCode Records - Question 1051 Height Checker

Attempt 1: Use .clone() and Arrays.sort()

class Solution {
    public int heightChecker(int[] heights) {
        int[] expected = heights.clone();
        Arrays.sort(expected);
        
        int count = 0;
        for (int i = 0; i < heights.length; i++) {
            if (expected[i] != heights[i]) {
                count++;
            }
        }
        
        return count;
    }
}
  • Runtime: 2 ms (Beats: 90.02%)
  • Memory: 41.52 MB (Beats: 21.08%)