forked from Hrudhay-H/Cpp_Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetcode_1051.cpp
More file actions
28 lines (26 loc) · 755 Bytes
/
Copy pathLeetcode_1051.cpp
File metadata and controls
28 lines (26 loc) · 755 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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
// 1051. Height Checker
class Solution {
public:
int heightChecker(vector<int>& heights) {
int res = 0;
int size = heights.size();
vector<int> exp(heights); // insert values of heightS in exp
sort(exp.begin() , exp.end()); //inbuilt func in c++ to sort vec
for(int i=0;i<exp.size();i++){
if(exp[i] != heights[i]){
res++;
}
}
return res;
}
};
int main() {
Solution s;
vector<int> heights = {1,1,4,2,1,3};
cout << s.heightChecker(heights) << endl; // Output: 3
return 0;
}