adding one more 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 1051: Height Checker](https://leetcode.com/problems/height-checker/) Solution: [p1051_heightchecker.cpp](../../leetcode/p1051_heightchecker.cpp)
|
- [Leetcode problem 977: Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array/). Solution: [p977_sortedsquare.cpp](../../leetcode/p977_sortedsquare.cpp)
|
||||||
- [Leetcode problem 211: Design Add and Search Words Data Structure](https://leetcode.com/problems/design-add-and-search-words-data-structure/)
|
- [Leetcode problem 1051: Height Checker](https://leetcode.com/problems/height-checker/). Solution: [p1051_heightchecker.cpp](../../leetcode/p1051_heightchecker.cpp)
|
||||||
- [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/)
|
||||||
|
|||||||
13
leetcode/p977_sortedsquare.cpp
Normal file
13
leetcode/p977_sortedsquare.cpp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
vector<int> sortedSquares(vector<int>& nums) {
|
||||||
|
int size = nums.size();
|
||||||
|
vector<int> squares;
|
||||||
|
// create the squares vector
|
||||||
|
for(int i=0;i<size;i++){
|
||||||
|
squares.push_back(nums[i]*nums[i]);
|
||||||
|
}
|
||||||
|
sort(squares.begin(),squares.end());
|
||||||
|
return squares;
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user