Skip to content

Commit db42308

Browse files
committed
1051 solved.
1 parent 74cf562 commit db42308

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
10311031
| | | | | | |
10321032
| 1049 | [Last Stone Weight II](https://leetcode.com/problems/last-stone-weight-ii/) | [] | [C++](1001-1500/1049-Last-Stone-Weight-II/cpp-1049/) | | |
10331033
| 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/) | | |
10351035
| 1052 | [Grumpy Bookstore Owner](https://leetcode.com/problems/grumpy-bookstore-owner/) | [] | [C++](1001-1500/1052-Grumpy-Bookstore-Owner/cpp-1052/) | | |
10361036
| | | | | | |
10371037
| 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/) | | |

0 commit comments

Comments
 (0)