-
-
Notifications
You must be signed in to change notification settings - Fork 297
/
Copy path1051.java
43 lines (43 loc) · 1.32 KB
/
1051.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
__________________________________________________________________________________________________
sample 0 ms submission
class Solution {
public int heightChecker(int[] heights) {
int[] count = new int[101] ;
for(int i : heights) {
count[i]++;
}
int[] lower = new int[101] ;
int[] heigher = new int[101] ;
int cnt = 0 ;
for(int i = 1 ; i < 101 ; i++) {
if(count[i] != 0) {
lower[i] = cnt ;
cnt += count[i] ;
heigher[i] = cnt - 1;
}
}
int res = 0 ;
for(int i = 0 ; i < heights.length ; i++) {
if((i )< lower[heights[i]] || (i) > heigher[heights[i]]) {
res++;
}
}
return res ;
}
}
__________________________________________________________________________________________________
sample 1 ms submission
class Solution {
public int heightChecker(int[] heights) {
int[] dup = (int[])heights.clone();
Arrays.sort(dup);
int res = 0;
for (int i = 0; i < heights.length; i++) {
if (heights[i] != dup[i]) {
res++;
}
}
return res;
}
}
__________________________________________________________________________________________________