File tree Expand file tree Collapse file tree 3 files changed +40
-1
lines changed
1001-1500/1051-Height-Checker/cpp-1051 Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Original file line number Diff line number Diff line change
1
+ cmake_minimum_required (VERSION 3.22 )
2
+ project (cpp_1051 )
3
+
4
+ set (CMAKE_CXX_STANDARD 14 )
5
+
6
+ add_executable (cpp_1051 main.cpp )
Original file line number Diff line number Diff line change
1
+ // / Source : https://leetcode.com/problems/height-checker/s
2
+ // / Author : liuyubobobo
3
+ // / Time : 2022-06-12
4
+
5
+ #include < iostream>
6
+ #include < vector>
7
+ #include < algorithm>
8
+
9
+ using namespace std ;
10
+
11
+
12
+ // / Sorting
13
+ // / Time Complexity: O(nlogn)
14
+ // / Space Complexity: O(n)
15
+ class Solution {
16
+ public:
17
+ int heightChecker (vector<int >& heights) {
18
+
19
+ vector<int > final (heights.begin (), heights.end ());
20
+ sort (final .begin (), final .end ());
21
+
22
+ int res = 0 ;
23
+ for (int i = 0 ; i < heights.size (); i ++)
24
+ res += heights[i] != final [i];
25
+ return res;
26
+ }
27
+ };
28
+
29
+
30
+ int main () {
31
+
32
+ return 0 ;
33
+ }
Original file line number Diff line number Diff line change @@ -1031,7 +1031,7 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
1031
1031
| | | | | | |
1032
1032
| 1049 | [ Last Stone Weight II] ( https://leetcode.com/problems/last-stone-weight-ii/ ) | [ 无] | [ C++] ( 1001-1500/1049-Last-Stone-Weight-II/cpp-1049/ ) | | |
1033
1033
| 1050 | Database Problem: [ Link] ( https://github.com/liuyubobobo/Play-Leetcode-Database/ ) | - | - | - | - |
1034
- | | | | | | |
1034
+ | 1051 | [ Height Checker ] ( https://leetcode.com/problems/height-checker/ ) | [ 无 ] | [ C++ ] ( 1001-1500/1051-Height-Checker/cpp-1051/ ) | | |
1035
1035
| 1052 | [ Grumpy Bookstore Owner] ( https://leetcode.com/problems/grumpy-bookstore-owner/ ) | [ 无] | [ C++] ( 1001-1500/1052-Grumpy-Bookstore-Owner/cpp-1052/ ) | | |
1036
1036
| | | | | | |
1037
1037
| 1059 | [ All Paths from Source Lead to Destination] ( https://leetcode.com/problems/all-paths-from-source-lead-to-destination/ ) | [ solution] ( https://leetcode.com/problems/all-paths-from-source-lead-to-destination/solution/ ) | [ C++] ( 1001-1500/1059-All-Paths-from-Source-Lead-to-Destination/cpp-1059/ ) | | |
You can’t perform that action at this time.
0 commit comments