Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 244f290

Browse files
committed
Add solution #1051
1 parent bc40ad5 commit 244f290

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

1051-height-checker.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@
274274
1037|[Valid Boomerang](./1037-valid-boomerang.js)|Easy|
275275
1041|[Robot Bounded In Circle](./1041-robot-bounded-in-circle.js)|Medium|
276276
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|
277278
1071|[Greatest Common Divisor of Strings](./1071-greatest-common-divisor-of-strings.js)|Easy|
278279
1081|[Smallest Subsequence of Distinct Characters](./1081-smallest-subsequence-of-distinct-characters.js)|Medium|
279280
1103|[Distribute Candies to People](./1103-distribute-candies-to-people.js)|Easy|

0 commit comments

Comments
 (0)