vault backup: 2022-07-10 10:26:30

This commit is contained in:
juan 2022-07-10 10:26:30 +08:00
parent 95cd8fd7b8
commit 3d64f44429
8 changed files with 41 additions and 2 deletions

View file

@ -23,6 +23,7 @@ tag:#CS_list_need_understanding
- [ ] [[Leetcode Binary-Tree-Preorder-Traversal]] - [ ] [[Leetcode Binary-Tree-Preorder-Traversal]]
- [ ] [[Leetcode Implement-Queue-Using-Stacks]] - [ ] [[Leetcode Implement-Queue-Using-Stacks]]
- [ ] [[Leetcode Reverse-Linked-List]] - [ ] [[Leetcode Reverse-Linked-List]]
- [ ] [[Leetcode Rotate-Array]]
@ -35,6 +36,7 @@ tag:#CS_list_need_practicing
- [ ] [[Leetcode Binary-Search]] - [ ] [[Leetcode Binary-Search]]
- [ ] [[Leetcode Binary-Tree-Postorder-Traversal]] - [ ] [[Leetcode Binary-Tree-Postorder-Traversal]]
- [ ] [[Leetcode Reverse-Linked-List]] - [ ] [[Leetcode Reverse-Linked-List]]
- [ ] [[Leetcode Rotate-Array]]
- [ ] [[Leetcode Validate-Binary-Search-Tree]] - [ ] [[Leetcode Validate-Binary-Search-Tree]]
@ -48,7 +50,6 @@ tag:#leetcode
- [[$filename]] - [[$filename]]
``` ```
- [[Leetcode Valid-Parentheses]]
- [[Leetcode Best-Time-To-Buy-And-Sell-Stock]] - [[Leetcode Best-Time-To-Buy-And-Sell-Stock]]
- [[Leetcode Binary-Search]] - [[Leetcode Binary-Search]]
- [[Leetcode Binary-Tree-Inorder-Traversal]] - [[Leetcode Binary-Tree-Inorder-Traversal]]
@ -75,13 +76,16 @@ tag:#leetcode
- [[Leetcode Remove-Linked-List-Elements]] - [[Leetcode Remove-Linked-List-Elements]]
- [[Leetcode Reshape-The-Matrix]] - [[Leetcode Reshape-The-Matrix]]
- [[Leetcode Reverse-Linked-List]] - [[Leetcode Reverse-Linked-List]]
- [[Leetcode Rotate-Array]]
- [[Leetcode Search-a-2D-Matrix]] - [[Leetcode Search-a-2D-Matrix]]
- [[Leetcode Search-In-a-Binary-Tree]] - [[Leetcode Search-In-a-Binary-Tree]]
- [[Leetcode Search-Insert-Position]] - [[Leetcode Search-Insert-Position]]
- [[Leetcode Squares-of-a-Sorted-Array]]
- [[Leetcode Symmetric-Tree]] - [[Leetcode Symmetric-Tree]]
- [[Leetcode Two-Sum]] - [[Leetcode Two-Sum]]
- [[Leetcode Two-Sum-IV-Input-Is-a-BST]] - [[Leetcode Two-Sum-IV-Input-Is-a-BST]]
- [[Leetcode Valid-Anagram]] - [[Leetcode Valid-Anagram]]
- [[Leetcode Valid-Parentheses]]
- [[Leetcode Valid-Sudoku]] - [[Leetcode Valid-Sudoku]]
- [[Leetcode Validate-Binary-Search-Tree]] - [[Leetcode Validate-Binary-Search-Tree]]
@ -107,7 +111,6 @@ tag:#DS tag:#coding_problem -tag:#template_remove_me
- [[$filename]] - [[$filename]]
``` ```
- [[Leetcode Valid-Parentheses]]
- [[Leetcode Best-Time-To-Buy-And-Sell-Stock]] - [[Leetcode Best-Time-To-Buy-And-Sell-Stock]]
- [[Leetcode Binary-Search]] - [[Leetcode Binary-Search]]
- [[Leetcode Binary-Tree-Inorder-Traversal]] - [[Leetcode Binary-Tree-Inorder-Traversal]]
@ -133,13 +136,16 @@ tag:#DS tag:#coding_problem -tag:#template_remove_me
- [[Leetcode Remove-Linked-List-Elements]] - [[Leetcode Remove-Linked-List-Elements]]
- [[Leetcode Reshape-The-Matrix]] - [[Leetcode Reshape-The-Matrix]]
- [[Leetcode Reverse-Linked-List]] - [[Leetcode Reverse-Linked-List]]
- [[Leetcode Rotate-Array]]
- [[Leetcode Search-a-2D-Matrix]] - [[Leetcode Search-a-2D-Matrix]]
- [[Leetcode Search-In-a-Binary-Tree]] - [[Leetcode Search-In-a-Binary-Tree]]
- [[Leetcode Search-Insert-Position]] - [[Leetcode Search-Insert-Position]]
- [[Leetcode Squares-of-a-Sorted-Array]]
- [[Leetcode Symmetric-Tree]] - [[Leetcode Symmetric-Tree]]
- [[Leetcode Two-Sum]] - [[Leetcode Two-Sum]]
- [[Leetcode Two-Sum-IV-Input-Is-a-BST]] - [[Leetcode Two-Sum-IV-Input-Is-a-BST]]
- [[Leetcode Valid-Anagram]] - [[Leetcode Valid-Anagram]]
- [[Leetcode Valid-Parentheses]]
- [[Leetcode Valid-Sudoku]] - [[Leetcode Valid-Sudoku]]
- [[Leetcode Validate-Binary-Search-Tree]] - [[Leetcode Validate-Binary-Search-Tree]]
@ -188,9 +194,11 @@ tag:#algorithm tag:#coding_problem -tag:#template_remove_me
- [[Leetcode Path-Sum]] - [[Leetcode Path-Sum]]
- [[Leetcode Ransom-Note]] - [[Leetcode Ransom-Note]]
- [[Leetcode Reverse-Linked-List]] - [[Leetcode Reverse-Linked-List]]
- [[Leetcode Rotate-Array]]
- [[Leetcode Search-a-2D-Matrix]] - [[Leetcode Search-a-2D-Matrix]]
- [[Leetcode Search-In-a-Binary-Tree]] - [[Leetcode Search-In-a-Binary-Tree]]
- [[Leetcode Search-Insert-Position]] - [[Leetcode Search-Insert-Position]]
- [[Leetcode Squares-of-a-Sorted-Array]]
- [[Leetcode Symmetric-Tree]] - [[Leetcode Symmetric-Tree]]
- [[Leetcode Two-Sum]] - [[Leetcode Two-Sum]]
- [[Leetcode Two-Sum-IV-Input-Is-a-BST]] - [[Leetcode Two-Sum-IV-Input-Is-a-BST]]

View file

@ -19,6 +19,7 @@ tag:#unordered_map OR tag:#two_pointers OR tag:#sort
- [[cpp_std_unordered_map]] - [[cpp_std_unordered_map]]
- [[Leetcode Merge-Sorted-Array]] - [[Leetcode Merge-Sorted-Array]]
- [[Leetcode Merge-Two-Sorted-Lists]] - [[Leetcode Merge-Two-Sorted-Lists]]
- [[Leetcode Squares-of-a-Sorted-Array]]
- [[Leetcode Two-Sum]] - [[Leetcode Two-Sum]]
- [[Two pointers approach]] - [[Two pointers approach]]

View file

@ -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 Merge-Two-Sorted-Lists]]
- [[Leetcode Reshape-The-Matrix]] - [[Leetcode Reshape-The-Matrix]]
- [[Leetcode Search-a-2D-Matrix]] - [[Leetcode Search-a-2D-Matrix]]
- [[Leetcode Squares-of-a-Sorted-Array]]
- [[Leetcode Valid-Sudoku]] - [[Leetcode Valid-Sudoku]]
- [[Two pointers approach]] - [[Two pointers approach]]

View file

@ -16,6 +16,7 @@ tag:#two_pointers
- [[Leetcode Intersection-of-Two-Arrays-II]] - [[Leetcode Intersection-of-Two-Arrays-II]]
- [[Leetcode Merge-Sorted-Array]] - [[Leetcode Merge-Sorted-Array]]
- [[Leetcode Squares-of-a-Sorted-Array]]
- [[Two pointers approach]] - [[Two pointers approach]]

View file

@ -25,7 +25,9 @@ tag:#recursion OR tag:#iteration OR tag:#array -tag:#Kadane_s_algorithm
- [[Leetcode Ransom-Note]] - [[Leetcode Ransom-Note]]
- [[Leetcode Reshape-The-Matrix]] - [[Leetcode Reshape-The-Matrix]]
- [[Leetcode Reverse-Linked-List]] - [[Leetcode Reverse-Linked-List]]
- [[Leetcode Rotate-Array]]
- [[Leetcode Search-Insert-Position]] - [[Leetcode Search-Insert-Position]]
- [[Leetcode Squares-of-a-Sorted-Array]]
- [[Leetcode Symmetric-Tree]] - [[Leetcode Symmetric-Tree]]
- [[Leetcode Two-Sum]] - [[Leetcode Two-Sum]]
- [[Leetcode Valid-Anagram]] - [[Leetcode Valid-Anagram]]

View file

@ -20,8 +20,10 @@
- [[Leetcode Merge-Sorted-Array]] - [[Leetcode Merge-Sorted-Array]]
- [[Leetcode Pascal's-Triangle]] - [[Leetcode Pascal's-Triangle]]
- [[Leetcode Ransom-Note]] - [[Leetcode Ransom-Note]]
- [[Leetcode Rotate-Array]]
- [[Leetcode Search-a-2D-Matrix]] - [[Leetcode Search-a-2D-Matrix]]
- [[Leetcode Search-Insert-Position]] - [[Leetcode Search-Insert-Position]]
- [[Leetcode Squares-of-a-Sorted-Array]]
- [[Leetcode Two-Sum]] - [[Leetcode Two-Sum]]
- [[Leetcode Valid-Anagram]] - [[Leetcode Valid-Anagram]]
- [[Leetcode Valid-Sudoku]] - [[Leetcode Valid-Sudoku]]

View file

@ -96,7 +96,30 @@ Remember to sanitize k, when k > size
Method 1: Method 1:
```cpp ```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: Method 2:

View file

@ -17,6 +17,7 @@ tag:#coding_problem tag:#two_pointers -tag:#template_remove_me
- [[Leetcode Intersection-of-Two-Arrays-II]] - [[Leetcode Intersection-of-Two-Arrays-II]]
- [[Leetcode Merge-Sorted-Array]] - [[Leetcode Merge-Sorted-Array]]
- [[Leetcode Merge-Two-Sorted-Lists]] - [[Leetcode Merge-Two-Sorted-Lists]]
- [[Leetcode Squares-of-a-Sorted-Array]]
##### Links: ##### Links: