update the leetcode problem
This commit is contained in:
@@ -144,6 +144,6 @@ bool earlier_date (const Date& a, const Date& b) {
|
|||||||
|
|
||||||
## 3.11 Exercises
|
## 3.11 Exercises
|
||||||
|
|
||||||
- [Leetcode problem 8: String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi/)
|
- [Leetcode problem 1051: Height Checker](https://leetcode.com/problems/height-checker/) [Solution](../../leetcode/p1051_heightchecker.cpp)
|
||||||
- [Leetcode problem 211: Design Add and Search Words Data Structure](https://leetcode.com/problems/design-add-and-search-words-data-structure/)
|
- [Leetcode problem 211: Design Add and Search Words Data Structure](https://leetcode.com/problems/design-add-and-search-words-data-structure/)
|
||||||
- [Leetcode problem 1662: Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/)
|
- [Leetcode problem 1662: Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/)
|
||||||
|
|||||||
15
leetcode/p1051_heightchecker.cpp
Normal file
15
leetcode/p1051_heightchecker.cpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
int heightChecker(vector<int>& heights) {
|
||||||
|
int count = 0;
|
||||||
|
int size = heights.size();
|
||||||
|
vector<int> expected(heights);
|
||||||
|
sort(expected.begin(),expected.end());
|
||||||
|
for(int i=0;i<size;i++){
|
||||||
|
if(heights[i]!=expected[i]){
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user