update the leetcode problem

This commit is contained in:
Jidong Xiao
2023-09-07 22:35:34 -04:00
parent 10ee772a1f
commit 47b932e9ed
2 changed files with 16 additions and 1 deletions

View File

@@ -144,6 +144,6 @@ bool earlier_date (const Date& a, const Date& b) {
## 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 1662: Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/)

View 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;
}
};