Skip to content

Commit 7263abf

Browse files
committed
Height Checker
1 parent c1b52a0 commit 7263abf

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

1051-height-checker.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Problem Link: https://leetcode.com/problems/height-checker/
3+
4+
5+
Students are asked to stand in non-decreasing order of heights for an annual photo.
6+
Return the minimum number of students not standing in the right positions. (This is the number of students that must move in order for all
7+
students to be standing in non-decreasing order of height.)
8+
9+
Example 1:
10+
Input: [1,1,4,2,1,3]
11+
Output: 3
12+
Explanation:
13+
Students with heights 4, 3 and the last 1 are not standing in the right positions.
14+
15+
Note:
16+
1 <= heights.length <= 100
17+
1 <= heights[i] <= 100
18+
"""
19+
class Solution(object):
20+
def heightChecker(self, heights):
21+
"""
22+
:type heights: List[int]
23+
:rtype: int
24+
"""
25+
s = sorted(heights)
26+
count = 0
27+
for i, h in enumerate(heights):
28+
if h != s[i]:
29+
count += 1
30+
return count

0 commit comments

Comments
 (0)