File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments