1051. Height Checker Easy
1/**
2 * [1051] Height Checker
3 *
4 * A school is trying to take an annual photo of all the students. The students are asked to stand in a single file line in non-decreasing order by height. Let this ordering be represented by the integer array expected where expected[i] is the expected height of the i^th student in line.
5 * You are given an integer array heights representing the current order that the students are standing in. Each heights[i] is the height of the i^th student in line (0-indexed).
6 * Return the number of indices where heights[i] != expected[i].
7 *
8 * Example 1:
9 *
10 * Input: heights = [1,1,4,2,1,3]
11 * Output: 3
12 * Explanation:
13 * heights: [1,1,<u>4</u>,2,<u>1</u>,<u>3</u>]
14 * expected: [1,1,<u>1</u>,2,<u>3</u>,<u>4</u>]
15 * Indices 2, 4, and 5 do not match.
16 *
17 * Example 2:
18 *
19 * Input: heights = [5,1,2,3,4]
20 * Output: 5
21 * Explanation:
22 * heights: [<u>5</u>,<u>1</u>,<u>2</u>,<u>3</u>,<u>4</u>]
23 * expected: [<u>1</u>,<u>2</u>,<u>3</u>,<u>4</u>,<u>5</u>]
24 * All indices do not match.
25 *
26 * Example 3:
27 *
28 * Input: heights = [1,2,3,4,5]
29 * Output: 0
30 * Explanation:
31 * heights: [1,2,3,4,5]
32 * expected: [1,2,3,4,5]
33 * All indices match.
34 *
35 *
36 * Constraints:
37 *
38 * 1 <= heights.length <= 100
39 * 1 <= heights[i] <= 100
40 *
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/height-checker/
45// discuss: https://leetcode.com/problems/height-checker/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50 pub fn height_checker(heights: Vec<i32>) -> i32 {
51 0
52 }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_1051() {
63 }
64}
65
Back
© 2025 bowen.ge All Rights Reserved.