-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeight Checker
More file actions
38 lines (36 loc) · 984 Bytes
/
Copy pathHeight Checker
File metadata and controls
38 lines (36 loc) · 984 Bytes
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
import java.util.Arrays;
class Solution {
public int heightChecker(int[] heights) {
int n=heights.length;
int count=0;
int temp;
int num[]=new int[n];
for(int k=0;k<n;k++){
num[k]=heights[k];
}
for (int i = 0; i <n; i++)
{
for (int j = i + 1; j <n; j++) {
if (num[i] > num[j])
{
temp = num[i];
num[i] = num[j];
num[j] = temp;
}
}
}
System.out.print("Array Elements in Ascending Order: ");
for (int i = 0; i < n-1; i++)
{
System.out.print(num[i] + ", ");
}
System.out.print(num[n- 1]);
for(int i=0;i<n;i++){
if(heights[i]==num[i])
continue;
else
count++;
}
return count;
}
}