vault backup: 2022-07-10 08:29:59
This commit is contained in:
parent
deabec3eae
commit
7f90edd5c8
|
@ -32,6 +32,7 @@ tag:#CS_list_need_practicing
|
||||||
- [ ] [[$filename]]
|
- [ ] [[$filename]]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- [ ] [[Leetcode Binary-Search]]
|
||||||
- [ ] [[Leetcode Binary-Tree-Postorder-Traversal]]
|
- [ ] [[Leetcode Binary-Tree-Postorder-Traversal]]
|
||||||
- [ ] [[Leetcode Reverse-Linked-List]]
|
- [ ] [[Leetcode Reverse-Linked-List]]
|
||||||
- [ ] [[Leetcode Validate-Binary-Search-Tree]]
|
- [ ] [[Leetcode Validate-Binary-Search-Tree]]
|
||||||
|
@ -49,10 +50,12 @@ tag:#leetcode
|
||||||
|
|
||||||
- [[Leetcode Valid-Parentheses]]
|
- [[Leetcode Valid-Parentheses]]
|
||||||
- [[Leetcode Best-Time-To-Buy-And-Sell-Stock]]
|
- [[Leetcode Best-Time-To-Buy-And-Sell-Stock]]
|
||||||
|
- [[Leetcode Binary-Search]]
|
||||||
- [[Leetcode Binary-Tree-Inorder-Traversal]]
|
- [[Leetcode Binary-Tree-Inorder-Traversal]]
|
||||||
- [[Leetcode Binary-Tree-Level-Order-Traversal]]
|
- [[Leetcode Binary-Tree-Level-Order-Traversal]]
|
||||||
- [[Leetcode Binary-Tree-Postorder-Traversal]]
|
- [[Leetcode Binary-Tree-Postorder-Traversal]]
|
||||||
- [[Leetcode Binary-Tree-Preorder-Traversal]]
|
- [[Leetcode Binary-Tree-Preorder-Traversal]]
|
||||||
|
- [[Leetcode First-Bad-Version]]
|
||||||
- [[Leetcode First-Unique-Character-In-a-String]]
|
- [[Leetcode First-Unique-Character-In-a-String]]
|
||||||
- [[Leetcode Implement-Queue-Using-Stacks]]
|
- [[Leetcode Implement-Queue-Using-Stacks]]
|
||||||
- [[Leetcode Insert-Into-a-Binary-Search-Tree]]
|
- [[Leetcode Insert-Into-a-Binary-Search-Tree]]
|
||||||
|
@ -74,6 +77,7 @@ tag:#leetcode
|
||||||
- [[Leetcode Reverse-Linked-List]]
|
- [[Leetcode Reverse-Linked-List]]
|
||||||
- [[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 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]]
|
||||||
|
@ -105,10 +109,12 @@ tag:#DS tag:#coding_problem -tag:#template_remove_me
|
||||||
|
|
||||||
- [[Leetcode Valid-Parentheses]]
|
- [[Leetcode Valid-Parentheses]]
|
||||||
- [[Leetcode Best-Time-To-Buy-And-Sell-Stock]]
|
- [[Leetcode Best-Time-To-Buy-And-Sell-Stock]]
|
||||||
|
- [[Leetcode Binary-Search]]
|
||||||
- [[Leetcode Binary-Tree-Inorder-Traversal]]
|
- [[Leetcode Binary-Tree-Inorder-Traversal]]
|
||||||
- [[Leetcode Binary-Tree-Level-Order-Traversal]]
|
- [[Leetcode Binary-Tree-Level-Order-Traversal]]
|
||||||
- [[Leetcode Binary-Tree-Postorder-Traversal]]
|
- [[Leetcode Binary-Tree-Postorder-Traversal]]
|
||||||
- [[Leetcode Binary-Tree-Preorder-Traversal]]
|
- [[Leetcode Binary-Tree-Preorder-Traversal]]
|
||||||
|
- [[Leetcode First-Bad-Version]]
|
||||||
- [[Leetcode First-Unique-Character-In-a-String]]
|
- [[Leetcode First-Unique-Character-In-a-String]]
|
||||||
- [[Leetcode Implement-Queue-Using-Stacks]]
|
- [[Leetcode Implement-Queue-Using-Stacks]]
|
||||||
- [[Leetcode Insert-Into-a-Binary-Search-Tree]]
|
- [[Leetcode Insert-Into-a-Binary-Search-Tree]]
|
||||||
|
@ -129,6 +135,7 @@ tag:#DS tag:#coding_problem -tag:#template_remove_me
|
||||||
- [[Leetcode Reverse-Linked-List]]
|
- [[Leetcode Reverse-Linked-List]]
|
||||||
- [[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 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]]
|
||||||
|
@ -160,10 +167,12 @@ tag:#algorithm tag:#coding_problem -tag:#template_remove_me
|
||||||
```
|
```
|
||||||
|
|
||||||
- [[Leetcode Best-Time-To-Buy-And-Sell-Stock]]
|
- [[Leetcode Best-Time-To-Buy-And-Sell-Stock]]
|
||||||
|
- [[Leetcode Binary-Search]]
|
||||||
- [[Leetcode Binary-Tree-Inorder-Traversal]]
|
- [[Leetcode Binary-Tree-Inorder-Traversal]]
|
||||||
- [[Leetcode Binary-Tree-Level-Order-Traversal]]
|
- [[Leetcode Binary-Tree-Level-Order-Traversal]]
|
||||||
- [[Leetcode Binary-Tree-Postorder-Traversal]]
|
- [[Leetcode Binary-Tree-Postorder-Traversal]]
|
||||||
- [[Leetcode Binary-Tree-Preorder-Traversal]]
|
- [[Leetcode Binary-Tree-Preorder-Traversal]]
|
||||||
|
- [[Leetcode First-Bad-Version]]
|
||||||
- [[Leetcode First-Unique-Character-In-a-String]]
|
- [[Leetcode First-Unique-Character-In-a-String]]
|
||||||
- [[Leetcode Insert-Into-a-Binary-Search-Tree]]
|
- [[Leetcode Insert-Into-a-Binary-Search-Tree]]
|
||||||
- [[Leetcode Intersection-of-Two-Arrays-II]]
|
- [[Leetcode Intersection-of-Two-Arrays-II]]
|
||||||
|
@ -181,6 +190,7 @@ tag:#algorithm tag:#coding_problem -tag:#template_remove_me
|
||||||
- [[Leetcode Reverse-Linked-List]]
|
- [[Leetcode Reverse-Linked-List]]
|
||||||
- [[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 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]]
|
||||||
|
|
|
@ -14,7 +14,12 @@ ___
|
||||||
tag:#coding_problem tag:#binary_search -tag:#template_remove_me
|
tag:#coding_problem tag:#binary_search -tag:#template_remove_me
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- [[Leetcode Binary-Search]]
|
||||||
|
- [[Leetcode First-Bad-Version]]
|
||||||
|
- [[Leetcode Lowest-Common-Ancestor-Of-a-Binary-Search-Tree]]
|
||||||
- [[Leetcode Search-a-2D-Matrix]]
|
- [[Leetcode Search-a-2D-Matrix]]
|
||||||
|
- [[Leetcode Search-Insert-Position]]
|
||||||
|
- [[Leetcode Two-Sum-IV-Input-Is-a-BST]]
|
||||||
|
|
||||||
|
|
||||||
##### Links:
|
##### Links:
|
||||||
|
|
|
@ -15,6 +15,7 @@ tag:#Kadane_s_algorithm
|
||||||
```
|
```
|
||||||
|
|
||||||
- [[Kadane's Algorithm]]
|
- [[Kadane's Algorithm]]
|
||||||
|
- [[Leetcode Maximum-Difference-Between-Increasing-Elements]]
|
||||||
- [[Leetcode Maxinum-subarray]]
|
- [[Leetcode Maxinum-subarray]]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,10 @@ tag:#binary_search
|
||||||
```
|
```
|
||||||
|
|
||||||
- [[Binary Search Algorithm]]
|
- [[Binary Search Algorithm]]
|
||||||
|
- [[Leetcode First-Bad-Version]]
|
||||||
- [[Leetcode Lowest-Common-Ancestor-Of-a-Binary-Search-Tree]]
|
- [[Leetcode Lowest-Common-Ancestor-Of-a-Binary-Search-Tree]]
|
||||||
- [[Leetcode Search-a-2D-Matrix]]
|
- [[Leetcode Search-a-2D-Matrix]]
|
||||||
|
- [[Leetcode Search-Insert-Position]]
|
||||||
- [[Leetcode Two-Sum-IV-Input-Is-a-BST]]
|
- [[Leetcode Two-Sum-IV-Input-Is-a-BST]]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ tag:#DFS
|
||||||
- [[Leetcode Binary-Tree-Preorder-Traversal]]
|
- [[Leetcode Binary-Tree-Preorder-Traversal]]
|
||||||
- [[Leetcode Insert-Into-a-Binary-Search-Tree]]
|
- [[Leetcode Insert-Into-a-Binary-Search-Tree]]
|
||||||
- [[Leetcode Invert-Binary-Tree]]
|
- [[Leetcode Invert-Binary-Tree]]
|
||||||
|
- [[Leetcode Lowest-Common-Ancestor-Of-a-Binary-Search-Tree]]
|
||||||
- [[Leetcode Maximum-Depth-Of-Binary-Tree]]
|
- [[Leetcode Maximum-Depth-Of-Binary-Tree]]
|
||||||
- [[Leetcode Path-Sum]]
|
- [[Leetcode Path-Sum]]
|
||||||
- [[Leetcode Search-In-a-Binary-Tree]]
|
- [[Leetcode Search-In-a-Binary-Tree]]
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
tag:#BFS
|
tag:#BFS
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- [[Breadth First Search]]
|
||||||
- [[Leetcode Maximum-Depth-Of-Binary-Tree]]
|
- [[Leetcode Maximum-Depth-Of-Binary-Tree]]
|
||||||
- [[Leetcode Search-In-a-Binary-Tree]]
|
- [[Leetcode Search-In-a-Binary-Tree]]
|
||||||
- [[Leetcode Symmetric-Tree]]
|
- [[Leetcode Symmetric-Tree]]
|
||||||
|
|
|
@ -22,6 +22,7 @@ tag:#DFS
|
||||||
- [[Leetcode Binary-Tree-Preorder-Traversal]]
|
- [[Leetcode Binary-Tree-Preorder-Traversal]]
|
||||||
- [[Leetcode Insert-Into-a-Binary-Search-Tree]]
|
- [[Leetcode Insert-Into-a-Binary-Search-Tree]]
|
||||||
- [[Leetcode Invert-Binary-Tree]]
|
- [[Leetcode Invert-Binary-Tree]]
|
||||||
|
- [[Leetcode Lowest-Common-Ancestor-Of-a-Binary-Search-Tree]]
|
||||||
- [[Leetcode Maximum-Depth-Of-Binary-Tree]]
|
- [[Leetcode Maximum-Depth-Of-Binary-Tree]]
|
||||||
- [[Leetcode Path-Sum]]
|
- [[Leetcode Path-Sum]]
|
||||||
- [[Leetcode Search-In-a-Binary-Tree]]
|
- [[Leetcode Search-In-a-Binary-Tree]]
|
||||||
|
|
|
@ -22,6 +22,7 @@ tag:#DFS
|
||||||
- [[Leetcode Binary-Tree-Postorder-Traversal]]
|
- [[Leetcode Binary-Tree-Postorder-Traversal]]
|
||||||
- [[Leetcode Insert-Into-a-Binary-Search-Tree]]
|
- [[Leetcode Insert-Into-a-Binary-Search-Tree]]
|
||||||
- [[Leetcode Invert-Binary-Tree]]
|
- [[Leetcode Invert-Binary-Tree]]
|
||||||
|
- [[Leetcode Lowest-Common-Ancestor-Of-a-Binary-Search-Tree]]
|
||||||
- [[Leetcode Maximum-Depth-Of-Binary-Tree]]
|
- [[Leetcode Maximum-Depth-Of-Binary-Tree]]
|
||||||
- [[Leetcode Path-Sum]]
|
- [[Leetcode Path-Sum]]
|
||||||
- [[Leetcode Search-In-a-Binary-Tree]]
|
- [[Leetcode Search-In-a-Binary-Tree]]
|
||||||
|
|
|
@ -18,6 +18,12 @@
|
||||||
tag:#binary_search
|
tag:#binary_search
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- [[Binary Search Algorithm]]
|
||||||
|
- [[Leetcode Binary-Search]]
|
||||||
|
- [[Leetcode Lowest-Common-Ancestor-Of-a-Binary-Search-Tree]]
|
||||||
|
- [[Leetcode Search-a-2D-Matrix]]
|
||||||
|
- [[Leetcode Search-Insert-Position]]
|
||||||
|
- [[Leetcode Two-Sum-IV-Input-Is-a-BST]]
|
||||||
|
|
||||||
|
|
||||||
##### Links:
|
##### Links:
|
||||||
|
|
|
@ -16,6 +16,8 @@ tag:#string OR tag:#hash_table
|
||||||
|
|
||||||
- [[cpp_std_unordered_map]]
|
- [[cpp_std_unordered_map]]
|
||||||
- [[Leetcode Ransom-Note]]
|
- [[Leetcode Ransom-Note]]
|
||||||
|
- [[Leetcode Two-Sum-IV-Input-Is-a-BST]]
|
||||||
|
- [[Leetcode Valid-Anagram]]
|
||||||
|
|
||||||
|
|
||||||
##### Links:
|
##### Links:
|
||||||
|
|
|
@ -22,6 +22,7 @@ tag:#DFS
|
||||||
- [[Leetcode Binary-Tree-Postorder-Traversal]]
|
- [[Leetcode Binary-Tree-Postorder-Traversal]]
|
||||||
- [[Leetcode Binary-Tree-Preorder-Traversal]]
|
- [[Leetcode Binary-Tree-Preorder-Traversal]]
|
||||||
- [[Leetcode Invert-Binary-Tree]]
|
- [[Leetcode Invert-Binary-Tree]]
|
||||||
|
- [[Leetcode Lowest-Common-Ancestor-Of-a-Binary-Search-Tree]]
|
||||||
- [[Leetcode Maximum-Depth-Of-Binary-Tree]]
|
- [[Leetcode Maximum-Depth-Of-Binary-Tree]]
|
||||||
- [[Leetcode Path-Sum]]
|
- [[Leetcode Path-Sum]]
|
||||||
- [[Leetcode Search-In-a-Binary-Tree]]
|
- [[Leetcode Search-In-a-Binary-Tree]]
|
||||||
|
|
|
@ -18,7 +18,9 @@ tag:#unordered_map OR tag:#two_pointers OR tag:#sort
|
||||||
- [[cpp_std_sort]]
|
- [[cpp_std_sort]]
|
||||||
- [[cpp_std_unordered_map]]
|
- [[cpp_std_unordered_map]]
|
||||||
- [[Leetcode Merge-Sorted-Array]]
|
- [[Leetcode Merge-Sorted-Array]]
|
||||||
|
- [[Leetcode Merge-Two-Sorted-Lists]]
|
||||||
- [[Leetcode Two-Sum]]
|
- [[Leetcode Two-Sum]]
|
||||||
|
- [[Two pointers approach]]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
tag:#recursion tag:#DFS
|
tag:#recursion tag:#DFS
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- [[Leetcode Insert-Into-a-Binary-Search-Tree]]
|
||||||
- [[Leetcode Path-Sum]]
|
- [[Leetcode Path-Sum]]
|
||||||
- [[Leetcode Symmetric-Tree]]
|
- [[Leetcode Symmetric-Tree]]
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
tag:#BFS
|
tag:#BFS
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- [[Breadth First Search]]
|
||||||
- [[Leetcode Binary-Tree-Level-Order-Traversal]]
|
- [[Leetcode Binary-Tree-Level-Order-Traversal]]
|
||||||
- [[Leetcode Search-In-a-Binary-Tree]]
|
- [[Leetcode Search-In-a-Binary-Tree]]
|
||||||
- [[Leetcode Symmetric-Tree]]
|
- [[Leetcode Symmetric-Tree]]
|
||||||
|
|
|
@ -19,6 +19,7 @@ tag:#Kadane_s_algorithm
|
||||||
|
|
||||||
- [[Kadane's Algorithm]]
|
- [[Kadane's Algorithm]]
|
||||||
- [[Leetcode Best-Time-To-Buy-And-Sell-Stock]]
|
- [[Leetcode Best-Time-To-Buy-And-Sell-Stock]]
|
||||||
|
- [[Leetcode Maximum-Difference-Between-Increasing-Elements]]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,15 @@
|
||||||
tag:#set OR tag:#multiset OR tag:#merge_sort OR tag:#vector OR tag:#two_pointers
|
tag:#set OR tag:#multiset OR tag:#merge_sort OR tag:#vector OR tag:#two_pointers
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- [[Binary Search Algorithm]]
|
||||||
- [[cpp_Range_based_for_loop]]
|
- [[cpp_Range_based_for_loop]]
|
||||||
- [[cpp_std_multiset]]
|
- [[cpp_std_multiset]]
|
||||||
- [[Leetcode Intersection-of-Two-Arrays-II]]
|
- [[Leetcode Intersection-of-Two-Arrays-II]]
|
||||||
|
- [[Leetcode Merge-Two-Sorted-Lists]]
|
||||||
|
- [[Leetcode Reshape-The-Matrix]]
|
||||||
|
- [[Leetcode Search-a-2D-Matrix]]
|
||||||
|
- [[Leetcode Valid-Sudoku]]
|
||||||
|
- [[Two pointers approach]]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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]]
|
||||||
|
- [[Two pointers approach]]
|
||||||
|
|
||||||
|
|
||||||
##### Links:
|
##### Links:
|
||||||
|
|
|
@ -14,9 +14,22 @@
|
||||||
tag:#recursion OR tag:#iteration OR tag:#array -tag:#Kadane_s_algorithm
|
tag:#recursion OR tag:#iteration OR tag:#array -tag:#Kadane_s_algorithm
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- [[Binary Search Algorithm]]
|
||||||
- [[cpp_Range_based_for_loop]]
|
- [[cpp_Range_based_for_loop]]
|
||||||
|
- [[Leetcode Binary-Search]]
|
||||||
|
- [[Leetcode First-Bad-Version]]
|
||||||
|
- [[Leetcode First-Unique-Character-In-a-String]]
|
||||||
|
- [[Leetcode Insert-Into-a-Binary-Search-Tree]]
|
||||||
|
- [[Leetcode Invert-Binary-Tree]]
|
||||||
|
- [[Leetcode Path-Sum]]
|
||||||
|
- [[Leetcode Ransom-Note]]
|
||||||
- [[Leetcode Reshape-The-Matrix]]
|
- [[Leetcode Reshape-The-Matrix]]
|
||||||
|
- [[Leetcode Reverse-Linked-List]]
|
||||||
|
- [[Leetcode Search-Insert-Position]]
|
||||||
|
- [[Leetcode Symmetric-Tree]]
|
||||||
- [[Leetcode Two-Sum]]
|
- [[Leetcode Two-Sum]]
|
||||||
|
- [[Leetcode Valid-Anagram]]
|
||||||
|
- [[Two pointers approach]]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ tag:#DFS
|
||||||
- [[Leetcode Binary-Tree-Preorder-Traversal]]
|
- [[Leetcode Binary-Tree-Preorder-Traversal]]
|
||||||
- [[Leetcode Insert-Into-a-Binary-Search-Tree]]
|
- [[Leetcode Insert-Into-a-Binary-Search-Tree]]
|
||||||
- [[Leetcode Invert-Binary-Tree]]
|
- [[Leetcode Invert-Binary-Tree]]
|
||||||
|
- [[Leetcode Lowest-Common-Ancestor-Of-a-Binary-Search-Tree]]
|
||||||
- [[Leetcode Maximum-Depth-Of-Binary-Tree]]
|
- [[Leetcode Maximum-Depth-Of-Binary-Tree]]
|
||||||
- [[Leetcode Search-In-a-Binary-Tree]]
|
- [[Leetcode Search-In-a-Binary-Tree]]
|
||||||
- [[Leetcode Symmetric-Tree]]
|
- [[Leetcode Symmetric-Tree]]
|
||||||
|
|
|
@ -16,6 +16,8 @@ tag:#hash_table
|
||||||
|
|
||||||
- [[cpp_std_unordered_map]]
|
- [[cpp_std_unordered_map]]
|
||||||
- [[Leetcode First-Unique-Character-In-a-String]]
|
- [[Leetcode First-Unique-Character-In-a-String]]
|
||||||
|
- [[Leetcode Two-Sum-IV-Input-Is-a-BST]]
|
||||||
|
- [[Leetcode Valid-Anagram]]
|
||||||
|
|
||||||
|
|
||||||
##### Links:
|
##### Links:
|
||||||
|
|
|
@ -12,11 +12,20 @@
|
||||||
(tag:#array OR tag:#vector) -tag:#Kadane_s_algorithm
|
(tag:#array OR tag:#vector) -tag:#Kadane_s_algorithm
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- [[Binary Search Algorithm]]
|
||||||
- [[cpp_Range_based_for_loop]]
|
- [[cpp_Range_based_for_loop]]
|
||||||
|
- [[Leetcode Binary-Search]]
|
||||||
|
- [[Leetcode First-Bad-Version]]
|
||||||
|
- [[Leetcode First-Unique-Character-In-a-String]]
|
||||||
- [[Leetcode Merge-Sorted-Array]]
|
- [[Leetcode Merge-Sorted-Array]]
|
||||||
- [[Leetcode Pascal's-Triangle]]
|
- [[Leetcode Pascal's-Triangle]]
|
||||||
|
- [[Leetcode Ransom-Note]]
|
||||||
|
- [[Leetcode Search-a-2D-Matrix]]
|
||||||
|
- [[Leetcode Search-Insert-Position]]
|
||||||
- [[Leetcode Two-Sum]]
|
- [[Leetcode Two-Sum]]
|
||||||
|
- [[Leetcode Valid-Anagram]]
|
||||||
- [[Leetcode Valid-Sudoku]]
|
- [[Leetcode Valid-Sudoku]]
|
||||||
|
- [[Two pointers approach]]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,14 @@
|
||||||
tag:#DFS OR tag:#BFS
|
tag:#DFS OR tag:#BFS
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- [[Breadth First Search]]
|
||||||
- [[Leetcode Binary-Tree-Inorder-Traversal]]
|
- [[Leetcode Binary-Tree-Inorder-Traversal]]
|
||||||
- [[Leetcode Binary-Tree-Level-Order-Traversal]]
|
- [[Leetcode Binary-Tree-Level-Order-Traversal]]
|
||||||
- [[Leetcode Binary-Tree-Postorder-Traversal]]
|
- [[Leetcode Binary-Tree-Postorder-Traversal]]
|
||||||
- [[Leetcode Binary-Tree-Preorder-Traversal]]
|
- [[Leetcode Binary-Tree-Preorder-Traversal]]
|
||||||
- [[Leetcode Insert-Into-a-Binary-Search-Tree]]
|
- [[Leetcode Insert-Into-a-Binary-Search-Tree]]
|
||||||
- [[Leetcode Invert-Binary-Tree]]
|
- [[Leetcode Invert-Binary-Tree]]
|
||||||
|
- [[Leetcode Lowest-Common-Ancestor-Of-a-Binary-Search-Tree]]
|
||||||
- [[Leetcode Maximum-Depth-Of-Binary-Tree]]
|
- [[Leetcode Maximum-Depth-Of-Binary-Tree]]
|
||||||
- [[Leetcode Path-Sum]]
|
- [[Leetcode Path-Sum]]
|
||||||
- [[Leetcode Symmetric-Tree]]
|
- [[Leetcode Symmetric-Tree]]
|
||||||
|
|
103
OJ notes/pages/Leetcode Search-Insert-Position.md
Normal file
103
OJ notes/pages/Leetcode Search-Insert-Position.md
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
# Leetcode Search-Insert-Position
|
||||||
|
|
||||||
|
#### 2022-07-09 10:25
|
||||||
|
|
||||||
|
> ##### Algorithms:
|
||||||
|
> #algorithm #binary_search
|
||||||
|
> ##### Data structures:
|
||||||
|
> #DS #array
|
||||||
|
> ##### Difficulty:
|
||||||
|
> #coding_problem #difficulty-easy
|
||||||
|
> ##### Additional tags:
|
||||||
|
> #leetcode
|
||||||
|
> ##### Revisions:
|
||||||
|
> N/A
|
||||||
|
|
||||||
|
##### Related topics:
|
||||||
|
```expander
|
||||||
|
tag:#binary_search
|
||||||
|
```
|
||||||
|
|
||||||
|
- [[Binary Search Algorithm]]
|
||||||
|
- [[Leetcode Binary-Search]]
|
||||||
|
- [[Leetcode First-Bad-Version]]
|
||||||
|
- [[Leetcode Lowest-Common-Ancestor-Of-a-Binary-Search-Tree]]
|
||||||
|
- [[Leetcode Search-a-2D-Matrix]]
|
||||||
|
- [[Leetcode Two-Sum-IV-Input-Is-a-BST]]
|
||||||
|
|
||||||
|
|
||||||
|
##### Links:
|
||||||
|
- [Link to problem](https://leetcode.com/problems/binary-search/)
|
||||||
|
___
|
||||||
|
### Problem
|
||||||
|
|
||||||
|
Given an array of integers `nums` which is sorted in ascending order, and an integer `target`, write a function to search `target` in `nums`. If `target` exists, then return its index. Otherwise, return `-1`.
|
||||||
|
|
||||||
|
You must write an algorithm with `O(log n)` runtime complexity.
|
||||||
|
|
||||||
|
#### Examples
|
||||||
|
|
||||||
|
**Example 1:**
|
||||||
|
|
||||||
|
**Input:** nums = [-1,0,3,5,9,12], target = 9
|
||||||
|
**Output:** 4
|
||||||
|
**Explanation:** 9 exists in nums and its index is 4
|
||||||
|
|
||||||
|
**Example 2:**
|
||||||
|
|
||||||
|
**Input:** nums = [-1,0,3,5,9,12], target = 2
|
||||||
|
**Output:** -1
|
||||||
|
**Explanation:** 2 does not exist in nums so return -1
|
||||||
|
|
||||||
|
#### Constraints
|
||||||
|
|
||||||
|
- `1 <= nums.length <= 104`
|
||||||
|
- `-104 < nums[i], target < 104`
|
||||||
|
- All the integers in `nums` are **unique**.
|
||||||
|
- `nums` is sorted in ascending order.
|
||||||
|
|
||||||
|
### Thoughts
|
||||||
|
|
||||||
|
> [!summary]
|
||||||
|
> This is a #binary_search problem.
|
||||||
|
|
||||||
|
similar to [[Leetcode First-Bad-Version]], this relies on the converging nature of Bi-search
|
||||||
|
|
||||||
|
if the value is found, simply return it
|
||||||
|
|
||||||
|
if not found, at the end, position `l - 1` should be smaller than val.
|
||||||
|
|
||||||
|
and position `l` should be bigger, which is the position for the answer:
|
||||||
|
```
|
||||||
|
If not, return the index where it would be if it were inserted in order.
|
||||||
|
```
|
||||||
|
|
||||||
|
### Solution
|
||||||
|
|
||||||
|
Iteration
|
||||||
|
```cpp
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
int searchInsert(vector<int>& nums, int target) {
|
||||||
|
// variant of bi-search
|
||||||
|
int r = nums.size() - 1;
|
||||||
|
int l = 0;
|
||||||
|
int mid, val;
|
||||||
|
|
||||||
|
do {
|
||||||
|
mid = l + (r - l) / 2;
|
||||||
|
val = nums[mid];
|
||||||
|
|
||||||
|
if (val == target) {
|
||||||
|
return mid;
|
||||||
|
} else if (val < target) {
|
||||||
|
l = mid + 1;
|
||||||
|
} else {
|
||||||
|
r = mid - 1;
|
||||||
|
}
|
||||||
|
} while (l <= r);
|
||||||
|
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
```
|
|
@ -16,8 +16,13 @@ tag:#vector OR tag:#vector_2d OR tag:#binary_search
|
||||||
|
|
||||||
- [[Binary Search Algorithm]]
|
- [[Binary Search Algorithm]]
|
||||||
- [[cpp_Range_based_for_loop]]
|
- [[cpp_Range_based_for_loop]]
|
||||||
|
- [[Leetcode Binary-Search]]
|
||||||
|
- [[Leetcode First-Bad-Version]]
|
||||||
|
- [[Leetcode Lowest-Common-Ancestor-Of-a-Binary-Search-Tree]]
|
||||||
- [[Leetcode Merge-Sorted-Array]]
|
- [[Leetcode Merge-Sorted-Array]]
|
||||||
- [[Leetcode Reshape-The-Matrix]]
|
- [[Leetcode Reshape-The-Matrix]]
|
||||||
|
- [[Leetcode Search-Insert-Position]]
|
||||||
|
- [[Leetcode Two-Sum-IV-Input-Is-a-BST]]
|
||||||
- [[Leetcode Valid-Sudoku]]
|
- [[Leetcode Valid-Sudoku]]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,14 @@
|
||||||
tag:#DFS OR tag:#BFS
|
tag:#DFS OR tag:#BFS
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- [[Breadth First Search]]
|
||||||
- [[Leetcode Binary-Tree-Inorder-Traversal]]
|
- [[Leetcode Binary-Tree-Inorder-Traversal]]
|
||||||
- [[Leetcode Binary-Tree-Level-Order-Traversal]]
|
- [[Leetcode Binary-Tree-Level-Order-Traversal]]
|
||||||
- [[Leetcode Binary-Tree-Postorder-Traversal]]
|
- [[Leetcode Binary-Tree-Postorder-Traversal]]
|
||||||
- [[Leetcode Binary-Tree-Preorder-Traversal]]
|
- [[Leetcode Binary-Tree-Preorder-Traversal]]
|
||||||
- [[Leetcode Insert-Into-a-Binary-Search-Tree]]
|
- [[Leetcode Insert-Into-a-Binary-Search-Tree]]
|
||||||
- [[Leetcode Invert-Binary-Tree]]
|
- [[Leetcode Invert-Binary-Tree]]
|
||||||
|
- [[Leetcode Lowest-Common-Ancestor-Of-a-Binary-Search-Tree]]
|
||||||
- [[Leetcode Maximum-Depth-Of-Binary-Tree]]
|
- [[Leetcode Maximum-Depth-Of-Binary-Tree]]
|
||||||
- [[Leetcode Path-Sum]]
|
- [[Leetcode Path-Sum]]
|
||||||
- [[Leetcode Search-In-a-Binary-Tree]]
|
- [[Leetcode Search-In-a-Binary-Tree]]
|
||||||
|
|
|
@ -19,10 +19,15 @@ tag:#BFS OR tag:#binary_search
|
||||||
```
|
```
|
||||||
|
|
||||||
- [[Binary Search Algorithm]]
|
- [[Binary Search Algorithm]]
|
||||||
|
- [[Breadth First Search]]
|
||||||
|
- [[Leetcode Binary-Search]]
|
||||||
- [[Leetcode Binary-Tree-Level-Order-Traversal]]
|
- [[Leetcode Binary-Tree-Level-Order-Traversal]]
|
||||||
|
- [[Leetcode First-Bad-Version]]
|
||||||
|
- [[Leetcode Lowest-Common-Ancestor-Of-a-Binary-Search-Tree]]
|
||||||
- [[Leetcode Maximum-Depth-Of-Binary-Tree]]
|
- [[Leetcode Maximum-Depth-Of-Binary-Tree]]
|
||||||
- [[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 Symmetric-Tree]]
|
- [[Leetcode Symmetric-Tree]]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,11 @@
|
||||||
tag:#vector
|
tag:#vector
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- [[Binary Search Algorithm]]
|
||||||
- [[cpp_Range_based_for_loop]]
|
- [[cpp_Range_based_for_loop]]
|
||||||
- [[Leetcode Merge-Sorted-Array]]
|
- [[Leetcode Merge-Sorted-Array]]
|
||||||
- [[Leetcode Reshape-The-Matrix]]
|
- [[Leetcode Reshape-The-Matrix]]
|
||||||
|
- [[Leetcode Search-a-2D-Matrix]]
|
||||||
|
|
||||||
|
|
||||||
##### Links:
|
##### Links:
|
||||||
|
|
|
@ -13,6 +13,8 @@ tag:#coding_problem tag:#array tag:#vector tag:#multiset -tag:#template_remove_m
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##### Links:
|
##### Links:
|
||||||
- [cppreference](https://en.cppreference.com/w/cpp/language/range-for)
|
- [cppreference](https://en.cppreference.com/w/cpp/language/range-for)
|
||||||
___
|
___
|
||||||
|
|
Loading…
Reference in a new issue