File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1051. Height Checker
3
+ * https://leetcode.com/problems/height-checker/
4
+ * Difficulty: Easy
5
+ *
6
+ * A school is trying to take an annual photo of all the students. The students are asked
7
+ * to stand in a single file line in non-decreasing order by height. Let this ordering be
8
+ * represented by the integer array expected where expected[i] is the expected height of
9
+ * the ith student in line.
10
+ *
11
+ * You are given an integer array heights representing the current order that the students
12
+ * are standing in. Each heights[i] is the height of the ith student in line (0-indexed).
13
+ *
14
+ * Return the number of indices where heights[i] != expected[i].
15
+ */
16
+
17
+ /**
18
+ * @param {number[] } heights
19
+ * @return {number }
20
+ */
21
+ var heightChecker = function ( heights ) {
22
+ return [ ...heights ]
23
+ . sort ( ( a , b ) => a - b )
24
+ . filter ( ( expected , i ) => heights [ i ] !== expected ) . length ;
25
+ } ;
Original file line number Diff line number Diff line change 274
274
1037|[ Valid Boomerang] ( ./1037-valid-boomerang.js ) |Easy|
275
275
1041|[ Robot Bounded In Circle] ( ./1041-robot-bounded-in-circle.js ) |Medium|
276
276
1047|[ Remove All Adjacent Duplicates In String] ( ./1047-remove-all-adjacent-duplicates-in-string.js ) |Easy|
277
+ 1051|[ Height Checker] ( ./1051-height-checker.js ) |Easy|
277
278
1071|[ Greatest Common Divisor of Strings] ( ./1071-greatest-common-divisor-of-strings.js ) |Easy|
278
279
1081|[ Smallest Subsequence of Distinct Characters] ( ./1081-smallest-subsequence-of-distinct-characters.js ) |Medium|
279
280
1103|[ Distribute Candies to People] ( ./1103-distribute-candies-to-people.js ) |Easy|
You can’t perform that action at this time.
0 commit comments