vault backup: 2022-07-10 10:26:30
This commit is contained in:
parent
95cd8fd7b8
commit
3d64f44429
|
@ -23,6 +23,7 @@ tag:#CS_list_need_understanding
|
|||
- [ ] [[Leetcode Binary-Tree-Preorder-Traversal]]
|
||||
- [ ] [[Leetcode Implement-Queue-Using-Stacks]]
|
||||
- [ ] [[Leetcode Reverse-Linked-List]]
|
||||
- [ ] [[Leetcode Rotate-Array]]
|
||||
|
||||
|
||||
|
||||
|
@ -35,6 +36,7 @@ tag:#CS_list_need_practicing
|
|||
- [ ] [[Leetcode Binary-Search]]
|
||||
- [ ] [[Leetcode Binary-Tree-Postorder-Traversal]]
|
||||
- [ ] [[Leetcode Reverse-Linked-List]]
|
||||
- [ ] [[Leetcode Rotate-Array]]
|
||||
- [ ] [[Leetcode Validate-Binary-Search-Tree]]
|
||||
|
||||
|
||||
|
@ -48,7 +50,6 @@ tag:#leetcode
|
|||
- [[$filename]]
|
||||
```
|
||||
|
||||
- [[Leetcode Valid-Parentheses]]
|
||||
- [[Leetcode Best-Time-To-Buy-And-Sell-Stock]]
|
||||
- [[Leetcode Binary-Search]]
|
||||
- [[Leetcode Binary-Tree-Inorder-Traversal]]
|
||||
|
@ -75,13 +76,16 @@ tag:#leetcode
|
|||
- [[Leetcode Remove-Linked-List-Elements]]
|
||||
- [[Leetcode Reshape-The-Matrix]]
|
||||
- [[Leetcode Reverse-Linked-List]]
|
||||
- [[Leetcode Rotate-Array]]
|
||||
- [[Leetcode Search-a-2D-Matrix]]
|
||||
- [[Leetcode Search-In-a-Binary-Tree]]
|
||||
- [[Leetcode Search-Insert-Position]]
|
||||
- [[Leetcode Squares-of-a-Sorted-Array]]
|
||||
- [[Leetcode Symmetric-Tree]]
|
||||
- [[Leetcode Two-Sum]]
|
||||
- [[Leetcode Two-Sum-IV-Input-Is-a-BST]]
|
||||
- [[Leetcode Valid-Anagram]]
|
||||
- [[Leetcode Valid-Parentheses]]
|
||||
- [[Leetcode Valid-Sudoku]]
|
||||
- [[Leetcode Validate-Binary-Search-Tree]]
|
||||
|
||||
|
@ -107,7 +111,6 @@ tag:#DS tag:#coding_problem -tag:#template_remove_me
|
|||
- [[$filename]]
|
||||
```
|
||||
|
||||
- [[Leetcode Valid-Parentheses]]
|
||||
- [[Leetcode Best-Time-To-Buy-And-Sell-Stock]]
|
||||
- [[Leetcode Binary-Search]]
|
||||
- [[Leetcode Binary-Tree-Inorder-Traversal]]
|
||||
|
@ -133,13 +136,16 @@ tag:#DS tag:#coding_problem -tag:#template_remove_me
|
|||
- [[Leetcode Remove-Linked-List-Elements]]
|
||||
- [[Leetcode Reshape-The-Matrix]]
|
||||
- [[Leetcode Reverse-Linked-List]]
|
||||
- [[Leetcode Rotate-Array]]
|
||||
- [[Leetcode Search-a-2D-Matrix]]
|
||||
- [[Leetcode Search-In-a-Binary-Tree]]
|
||||
- [[Leetcode Search-Insert-Position]]
|
||||
- [[Leetcode Squares-of-a-Sorted-Array]]
|
||||
- [[Leetcode Symmetric-Tree]]
|
||||
- [[Leetcode Two-Sum]]
|
||||
- [[Leetcode Two-Sum-IV-Input-Is-a-BST]]
|
||||
- [[Leetcode Valid-Anagram]]
|
||||
- [[Leetcode Valid-Parentheses]]
|
||||
- [[Leetcode Valid-Sudoku]]
|
||||
- [[Leetcode Validate-Binary-Search-Tree]]
|
||||
|
||||
|
@ -188,9 +194,11 @@ tag:#algorithm tag:#coding_problem -tag:#template_remove_me
|
|||
- [[Leetcode Path-Sum]]
|
||||
- [[Leetcode Ransom-Note]]
|
||||
- [[Leetcode Reverse-Linked-List]]
|
||||
- [[Leetcode Rotate-Array]]
|
||||
- [[Leetcode Search-a-2D-Matrix]]
|
||||
- [[Leetcode Search-In-a-Binary-Tree]]
|
||||
- [[Leetcode Search-Insert-Position]]
|
||||
- [[Leetcode Squares-of-a-Sorted-Array]]
|
||||
- [[Leetcode Symmetric-Tree]]
|
||||
- [[Leetcode Two-Sum]]
|
||||
- [[Leetcode Two-Sum-IV-Input-Is-a-BST]]
|
||||
|
|
|
@ -19,6 +19,7 @@ tag:#unordered_map OR tag:#two_pointers OR tag:#sort
|
|||
- [[cpp_std_unordered_map]]
|
||||
- [[Leetcode Merge-Sorted-Array]]
|
||||
- [[Leetcode Merge-Two-Sorted-Lists]]
|
||||
- [[Leetcode Squares-of-a-Sorted-Array]]
|
||||
- [[Leetcode Two-Sum]]
|
||||
- [[Two pointers approach]]
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ tag:#set OR tag:#multiset OR tag:#merge_sort OR tag:#vector OR tag:#two_pointers
|
|||
- [[Leetcode Merge-Two-Sorted-Lists]]
|
||||
- [[Leetcode Reshape-The-Matrix]]
|
||||
- [[Leetcode Search-a-2D-Matrix]]
|
||||
- [[Leetcode Squares-of-a-Sorted-Array]]
|
||||
- [[Leetcode Valid-Sudoku]]
|
||||
- [[Two pointers approach]]
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ tag:#two_pointers
|
|||
|
||||
- [[Leetcode Intersection-of-Two-Arrays-II]]
|
||||
- [[Leetcode Merge-Sorted-Array]]
|
||||
- [[Leetcode Squares-of-a-Sorted-Array]]
|
||||
- [[Two pointers approach]]
|
||||
|
||||
|
||||
|
|
|
@ -25,7 +25,9 @@ tag:#recursion OR tag:#iteration OR tag:#array -tag:#Kadane_s_algorithm
|
|||
- [[Leetcode Ransom-Note]]
|
||||
- [[Leetcode Reshape-The-Matrix]]
|
||||
- [[Leetcode Reverse-Linked-List]]
|
||||
- [[Leetcode Rotate-Array]]
|
||||
- [[Leetcode Search-Insert-Position]]
|
||||
- [[Leetcode Squares-of-a-Sorted-Array]]
|
||||
- [[Leetcode Symmetric-Tree]]
|
||||
- [[Leetcode Two-Sum]]
|
||||
- [[Leetcode Valid-Anagram]]
|
||||
|
|
|
@ -20,8 +20,10 @@
|
|||
- [[Leetcode Merge-Sorted-Array]]
|
||||
- [[Leetcode Pascal's-Triangle]]
|
||||
- [[Leetcode Ransom-Note]]
|
||||
- [[Leetcode Rotate-Array]]
|
||||
- [[Leetcode Search-a-2D-Matrix]]
|
||||
- [[Leetcode Search-Insert-Position]]
|
||||
- [[Leetcode Squares-of-a-Sorted-Array]]
|
||||
- [[Leetcode Two-Sum]]
|
||||
- [[Leetcode Valid-Anagram]]
|
||||
- [[Leetcode Valid-Sudoku]]
|
||||
|
|
|
@ -96,7 +96,30 @@ Remember to sanitize k, when k > size
|
|||
Method 1:
|
||||
|
||||
```cpp
|
||||
class Solution {
|
||||
void swap(vector<int> &nums, int l, int r) {
|
||||
int temp = nums[l];
|
||||
nums[l] = nums[r];
|
||||
nums[r] = temp;
|
||||
}
|
||||
void reverse(vector<int> &nums, int l, int r) {
|
||||
while (l < r) {
|
||||
swap(nums, l, r);
|
||||
l++;
|
||||
r--;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
void rotate(vector<int> &nums, int k) {
|
||||
const int size = nums.size();
|
||||
k = k % size;
|
||||
// Reversion
|
||||
reverse(nums, 0, size - k - 1);
|
||||
reverse(nums, size - k, size - 1);
|
||||
reverse(nums, 0, size - 1);
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
Method 2:
|
||||
|
|
|
@ -17,6 +17,7 @@ tag:#coding_problem tag:#two_pointers -tag:#template_remove_me
|
|||
- [[Leetcode Intersection-of-Two-Arrays-II]]
|
||||
- [[Leetcode Merge-Sorted-Array]]
|
||||
- [[Leetcode Merge-Two-Sorted-Lists]]
|
||||
- [[Leetcode Squares-of-a-Sorted-Array]]
|
||||
|
||||
|
||||
##### Links:
|
||||
|
|
Loading…
Reference in a new issue