diff --git a/.obsidian/appearance.json b/.obsidian/appearance.json index d9941ff..0f1a331 100644 --- a/.obsidian/appearance.json +++ b/.obsidian/appearance.json @@ -1,5 +1,5 @@ { - "theme": "moonstone", + "theme": "obsidian", "translucency": true, "cssTheme": "Prism", "interfaceFontFamily": "IBM Plex Sans", diff --git a/.obsidian/graph.json b/.obsidian/graph.json index 8bb286a..3a9362a 100644 --- a/.obsidian/graph.json +++ b/.obsidian/graph.json @@ -30,15 +30,15 @@ } ], "collapse-display": false, - "showArrow": false, + "showArrow": true, "textFadeMultiplier": 0, "nodeSizeMultiplier": 1, "lineSizeMultiplier": 1, "collapse-forces": false, - "centerStrength": 0.518713248970312, - "repelStrength": 10, - "linkStrength": 1, - "linkDistance": 250, - "scale": 0.9747267101258579, - "close": true + "centerStrength": 0.5, + "repelStrength": 10.5952380952381, + "linkStrength": 0.505952380952381, + "linkDistance": 259, + "scale": 0.34081054256054544, + "close": false } \ No newline at end of file diff --git a/OJ notes/OJ-index.md b/OJ notes/OJ-index.md index ac5efad..06a96b4 100644 --- a/OJ notes/OJ-index.md +++ b/OJ notes/OJ-index.md @@ -35,9 +35,9 @@ This is where I store notes about CS #### Topics that needs care -- #sliding_window -- #Kadane_s_algorithm -- #greedy +- #sliding_window +- #Kadane_s_algorithm +- #greedy ## Websites diff --git a/OJ notes/pages/Binary Search Algorithm.md b/OJ notes/pages/Binary Search Algorithm.md index 9c4503b..2edcf12 100644 --- a/OJ notes/pages/Binary Search Algorithm.md +++ b/OJ notes/pages/Binary Search Algorithm.md @@ -14,7 +14,7 @@ ##### Difficulty: -#CS_analysis #difficulty-easy +#CS_analysis #difficulty_easy ##### Related problems: diff --git a/OJ notes/pages/Bit-Manipulation count true trick.md b/OJ notes/pages/Bit-Manipulation count true trick.md index 38389fc..71f9905 100644 --- a/OJ notes/pages/Bit-Manipulation count true trick.md +++ b/OJ notes/pages/Bit-Manipulation count true trick.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #CS_analysis #difficulty-easy +> #CS_analysis #difficulty_easy > > ##### Additional tags: diff --git a/OJ notes/pages/Breadth First Search.md b/OJ notes/pages/Breadth First Search.md index 76c507a..db5d757 100644 --- a/OJ notes/pages/Breadth First Search.md +++ b/OJ notes/pages/Breadth First Search.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #CS_analysis #difficulty- +> #CS_analysis #difficulty_ > > ##### Additional tags: diff --git a/OJ notes/pages/Floyd's Cycle Finding Algorithm.md b/OJ notes/pages/Floyd's Cycle Finding Algorithm.md index b06da32..b99fcaf 100644 --- a/OJ notes/pages/Floyd's Cycle Finding Algorithm.md +++ b/OJ notes/pages/Floyd's Cycle Finding Algorithm.md @@ -14,7 +14,7 @@ ##### Difficulty: -#CS_analysis #difficulty-easy +#CS_analysis #difficulty_easy ##### Related problems: diff --git a/OJ notes/pages/Greedy Algorithm.md b/OJ notes/pages/Greedy Algorithm.md index 297d4f1..ee90747 100644 --- a/OJ notes/pages/Greedy Algorithm.md +++ b/OJ notes/pages/Greedy Algorithm.md @@ -4,7 +4,7 @@ > ##### Algorithms: > -> #algorithm #greedy +> #algorithm #greedy > > ##### Difficulty: > diff --git a/OJ notes/pages/Kadane's Algorithm.md b/OJ notes/pages/Kadane's Algorithm.md index da2ce8d..9af3436 100644 --- a/OJ notes/pages/Kadane's Algorithm.md +++ b/OJ notes/pages/Kadane's Algorithm.md @@ -14,7 +14,7 @@ ##### Difficulty: -#CS_analysis #difficulty-easy +#CS_analysis #difficulty_easy ##### Time complexity: diff --git a/OJ notes/pages/Leetcode 01-Matrix.md b/OJ notes/pages/Leetcode 01-Matrix.md index 5490ec2..c29b77b 100644 --- a/OJ notes/pages/Leetcode 01-Matrix.md +++ b/OJ notes/pages/Leetcode 01-Matrix.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Add-Strings.md b/OJ notes/pages/Leetcode Add-Strings.md index fe79c9a..34250d5 100644 --- a/OJ notes/pages/Leetcode Add-Strings.md +++ b/OJ notes/pages/Leetcode Add-Strings.md @@ -4,15 +4,15 @@ > ##### Data structures: > -> #DS #string +> #DS #string > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > -> #leetcode +> #leetcode > > ##### Revisions: > @@ -49,9 +49,9 @@ You must solve the problem without using any built-in library for handling large #### Constraints -- `1 <= num1.length, num2.length <= 104` -- `num1` and `num2` consist of only digits. -- `num1` and `num2` don't have any leading zeros except for the zero itself. +- `1 <= num1.length, num2.length <= 104` +- `num1` and `num2` consist of only digits. +- `num1` and `num2` don't have any leading zeros except for the zero itself. ### Thoughts @@ -87,4 +87,4 @@ public: return ans; } }; -``` \ No newline at end of file +``` diff --git a/OJ notes/pages/Leetcode Average-Salary-Excluding-the-Minimum-and-Maximum-Salary.md b/OJ notes/pages/Leetcode Average-Salary-Excluding-the-Minimum-and-Maximum-Salary.md index a8e362a..1b08715 100644 --- a/OJ notes/pages/Leetcode Average-Salary-Excluding-the-Minimum-and-Maximum-Salary.md +++ b/OJ notes/pages/Leetcode Average-Salary-Excluding-the-Minimum-and-Maximum-Salary.md @@ -4,7 +4,7 @@ > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Best-Time-To-Buy-And-Sell-Stock.md b/OJ notes/pages/Leetcode Best-Time-To-Buy-And-Sell-Stock.md index 5d349cd..0e65300 100644 --- a/OJ notes/pages/Leetcode Best-Time-To-Buy-And-Sell-Stock.md +++ b/OJ notes/pages/Leetcode Best-Time-To-Buy-And-Sell-Stock.md @@ -14,7 +14,7 @@ ##### Difficulty: -#leetcode #coding_problem #difficulty-easy +#leetcode #coding_problem #difficulty_easy ##### Related topics: diff --git a/OJ notes/pages/Leetcode Binary-Search.md b/OJ notes/pages/Leetcode Binary-Search.md index 9f2d7a2..e0a6cc4 100644 --- a/OJ notes/pages/Leetcode Binary-Search.md +++ b/OJ notes/pages/Leetcode Binary-Search.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Binary-Tree-Inorder-Traversal.md b/OJ notes/pages/Leetcode Binary-Tree-Inorder-Traversal.md index dd72c39..ff97e14 100644 --- a/OJ notes/pages/Leetcode Binary-Tree-Inorder-Traversal.md +++ b/OJ notes/pages/Leetcode Binary-Tree-Inorder-Traversal.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Binary-Tree-Level-Order-Traversal.md b/OJ notes/pages/Leetcode Binary-Tree-Level-Order-Traversal.md index 3ca8cfd..fd03dff 100644 --- a/OJ notes/pages/Leetcode Binary-Tree-Level-Order-Traversal.md +++ b/OJ notes/pages/Leetcode Binary-Tree-Level-Order-Traversal.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Binary-Tree-Postorder-Traversal.md b/OJ notes/pages/Leetcode Binary-Tree-Postorder-Traversal.md index 5a51334..83ccf9a 100644 --- a/OJ notes/pages/Leetcode Binary-Tree-Postorder-Traversal.md +++ b/OJ notes/pages/Leetcode Binary-Tree-Postorder-Traversal.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty- +> #coding_problem #difficulty_ > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Binary-Tree-Preorder-Traversal.md b/OJ notes/pages/Leetcode Binary-Tree-Preorder-Traversal.md index e7afcb4..fe14b18 100644 --- a/OJ notes/pages/Leetcode Binary-Tree-Preorder-Traversal.md +++ b/OJ notes/pages/Leetcode Binary-Tree-Preorder-Traversal.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Check-If-It-Is-a-Straight-Line.md b/OJ notes/pages/Leetcode Check-If-It-Is-a-Straight-Line.md index 782233d..bcc12cb 100644 --- a/OJ notes/pages/Leetcode Check-If-It-Is-a-Straight-Line.md +++ b/OJ notes/pages/Leetcode Check-If-It-Is-a-Straight-Line.md @@ -8,7 +8,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Climbing-Chairs.md b/OJ notes/pages/Leetcode Climbing-Chairs.md index f7498a2..ba38c5a 100644 --- a/OJ notes/pages/Leetcode Climbing-Chairs.md +++ b/OJ notes/pages/Leetcode Climbing-Chairs.md @@ -8,7 +8,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Combinations.md b/OJ notes/pages/Leetcode Combinations.md index 73b256b..2b751bb 100644 --- a/OJ notes/pages/Leetcode Combinations.md +++ b/OJ notes/pages/Leetcode Combinations.md @@ -8,7 +8,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Count-Odd-Numbers-in-an-Interval-Range.md b/OJ notes/pages/Leetcode Count-Odd-Numbers-in-an-Interval-Range.md index 30cca66..a39c56c 100644 --- a/OJ notes/pages/Leetcode Count-Odd-Numbers-in-an-Interval-Range.md +++ b/OJ notes/pages/Leetcode Count-Odd-Numbers-in-an-Interval-Range.md @@ -8,7 +8,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Design-Hash.md b/OJ notes/pages/Leetcode Design-Hash.md index 1fcabd3..fbe3246 100644 --- a/OJ notes/pages/Leetcode Design-Hash.md +++ b/OJ notes/pages/Leetcode Design-Hash.md @@ -8,7 +8,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode First-Bad-Version.md b/OJ notes/pages/Leetcode First-Bad-Version.md index bb0f947..279247f 100644 --- a/OJ notes/pages/Leetcode First-Bad-Version.md +++ b/OJ notes/pages/Leetcode First-Bad-Version.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode First-Unique-Character-In-a-String.md b/OJ notes/pages/Leetcode First-Unique-Character-In-a-String.md index 2a85238..5554d76 100644 --- a/OJ notes/pages/Leetcode First-Unique-Character-In-a-String.md +++ b/OJ notes/pages/Leetcode First-Unique-Character-In-a-String.md @@ -14,7 +14,7 @@ ##### Difficulty: -#leetcode #coding_problem #difficulty-easy +#leetcode #coding_problem #difficulty_easy ##### Related topics: diff --git a/OJ notes/pages/Leetcode Flood-Fill.md b/OJ notes/pages/Leetcode Flood-Fill.md index bda6afa..56e7ccf 100644 --- a/OJ notes/pages/Leetcode Flood-Fill.md +++ b/OJ notes/pages/Leetcode Flood-Fill.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Group-Anagrams.md b/OJ notes/pages/Leetcode Group-Anagrams.md index 3a56d06..f31deda 100644 --- a/OJ notes/pages/Leetcode Group-Anagrams.md +++ b/OJ notes/pages/Leetcode Group-Anagrams.md @@ -8,11 +8,11 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > -> #leetcode +> #leetcode > > ##### Revisions: > @@ -55,9 +55,9 @@ An **Anagram** is a word or phrase formed by rearranging the letters of a differ #### Constraints -- `1 <= strs.length <= 104` -- `0 <= strs[i].length <= 100` -- `strs[i]` consists of lowercase English letters. +- `1 <= strs.length <= 104` +- `0 <= strs[i].length <= 100` +- `strs[i]` consists of lowercase English letters. ### Thoughts @@ -66,8 +66,9 @@ An **Anagram** is a word or phrase formed by rearranging the letters of a differ #### Two way hash table -This one can be solved simply using two-way hash tables, +This one can be solved simply using two-way hash tables, consisting of two hash tables: + - ana2id: turn anagram into an id - id2str: turn id into strings that has the anagrams @@ -76,6 +77,7 @@ CPP-style initialization of C's array. > [!tip] > CPP-style initialization of C array #tip +> > ```cpp > array ana = {}; > ``` @@ -83,12 +85,12 @@ CPP-style initialization of C's array. Note that vectors doesn't work in unordered hash maps, unless we use custom hash functions. -And arrays in c style definition (`int arr[26];`) will be +And arrays in c style definition (`int arr[26];`) will be hashed according to address, not conte`nt. #### Alternative method -By using sorted strings as keys, we can also solve this +By using sorted strings as keys, we can also solve this problem. Since the input is lowercase English letters, counting @@ -135,4 +137,4 @@ public: Counting sort -#TODO: solve using counting sort \ No newline at end of file +#TODO: solve using counting sort diff --git a/OJ notes/pages/Leetcode Happy-Number.md b/OJ notes/pages/Leetcode Happy-Number.md index 85c2876..b2add03 100644 --- a/OJ notes/pages/Leetcode Happy-Number.md +++ b/OJ notes/pages/Leetcode Happy-Number.md @@ -8,7 +8,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode House-Robber.md b/OJ notes/pages/Leetcode House-Robber.md index 1e517d3..420a6c1 100644 --- a/OJ notes/pages/Leetcode House-Robber.md +++ b/OJ notes/pages/Leetcode House-Robber.md @@ -8,7 +8,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Implement-Queue-Using-Stacks.md b/OJ notes/pages/Leetcode Implement-Queue-Using-Stacks.md index 4a67613..8baa81c 100644 --- a/OJ notes/pages/Leetcode Implement-Queue-Using-Stacks.md +++ b/OJ notes/pages/Leetcode Implement-Queue-Using-Stacks.md @@ -8,7 +8,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Increasing-Triplet-Subsequence.md b/OJ notes/pages/Leetcode Increasing-Triplet-Subsequence.md index 0cf15a8..a1ba7e5 100644 --- a/OJ notes/pages/Leetcode Increasing-Triplet-Subsequence.md +++ b/OJ notes/pages/Leetcode Increasing-Triplet-Subsequence.md @@ -4,19 +4,19 @@ > ##### Algorithms: > -> #algorithm #greedy +> #algorithm #greedy > > ##### Data structures: > -> #DS #array +> #DS #array > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > -> #leetcode #CS_list_need_understanding +> #leetcode #CS_list_need_understanding > > ##### Revisions: > @@ -55,8 +55,8 @@ Given an integer array `nums`, return `true` _if there exists a triple of indice #### Constraints -- `1 <= nums.length <= 5 * 105` -- `-231 <= nums[i] <= 231 - 1` +- `1 <= nums.length <= 5 * 105` +- `-231 <= nums[i] <= 231 - 1` ### Thoughts @@ -67,21 +67,21 @@ Use two variables: `small` and `big` to keep track of stuff. For each element, there are three possibilities: -- the element is smaller than `small`, assign the element - to `small` +- the element is smaller than `small`, assign the element + to `small` -> `small` and `big` doesn't represent `i` and `j`, +> `small` and `big` doesn't represent `i` and `j`, > accurately, they get updated lazily. > And because we don't need to show `i`, `j`, `k`, this -> will be just fine +> will be just fine - the element is greater than `small`: - - the element is smaller than `big`, change `big`, this - allows more possibilities - - the element is bigger than `big`, found, exit loop. + - the element is smaller than `big`, change `big`, this + allows more possibilities + - the element is bigger than `big`, found, exit loop. > #### Why not #stack ? -> +> > Similar to [[Leetcode Next-Greater-Element-I]], the property > of stack can be used for **continuity** related problem, but > here we don't need this. @@ -111,4 +111,4 @@ public: return false; } }; -``` \ No newline at end of file +``` diff --git a/OJ notes/pages/Leetcode Insert-Into-a-Binary-Search-Tree.md b/OJ notes/pages/Leetcode Insert-Into-a-Binary-Search-Tree.md index 86b239a..ee3daf5 100644 --- a/OJ notes/pages/Leetcode Insert-Into-a-Binary-Search-Tree.md +++ b/OJ notes/pages/Leetcode Insert-Into-a-Binary-Search-Tree.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Intersection-of-Two-Arrays-II.md b/OJ notes/pages/Leetcode Intersection-of-Two-Arrays-II.md index 9b39511..3392fac 100644 --- a/OJ notes/pages/Leetcode Intersection-of-Two-Arrays-II.md +++ b/OJ notes/pages/Leetcode Intersection-of-Two-Arrays-II.md @@ -16,7 +16,7 @@ ##### Difficulty: -#leetcode #coding_problem #difficulty-easy +#leetcode #coding_problem #difficulty_easy ##### Related topics: diff --git a/OJ notes/pages/Leetcode Invert-Binary-Tree.md b/OJ notes/pages/Leetcode Invert-Binary-Tree.md index df01827..55681ca 100644 --- a/OJ notes/pages/Leetcode Invert-Binary-Tree.md +++ b/OJ notes/pages/Leetcode Invert-Binary-Tree.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Largest-Perimeter-Triangle.md b/OJ notes/pages/Leetcode Largest-Perimeter-Triangle.md index dbeda5d..33e5c33 100644 --- a/OJ notes/pages/Leetcode Largest-Perimeter-Triangle.md +++ b/OJ notes/pages/Leetcode Largest-Perimeter-Triangle.md @@ -8,7 +8,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Letter-Case-Combination.md b/OJ notes/pages/Leetcode Letter-Case-Combination.md index fb892e8..ecc8db8 100644 --- a/OJ notes/pages/Leetcode Letter-Case-Combination.md +++ b/OJ notes/pages/Leetcode Letter-Case-Combination.md @@ -8,7 +8,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Linked-List-Cycle.md b/OJ notes/pages/Leetcode Linked-List-Cycle.md index 8ebb9f0..e9b45e0 100644 --- a/OJ notes/pages/Leetcode Linked-List-Cycle.md +++ b/OJ notes/pages/Leetcode Linked-List-Cycle.md @@ -14,7 +14,7 @@ ##### Difficulty: -#leetcode #coding_problem #difficulty-easy +#leetcode #coding_problem #difficulty_easy ##### Related topics: diff --git a/OJ notes/pages/Leetcode Longest-Palindrome.md b/OJ notes/pages/Leetcode Longest-Palindrome.md index 321ecd0..09fc8e9 100644 --- a/OJ notes/pages/Leetcode Longest-Palindrome.md +++ b/OJ notes/pages/Leetcode Longest-Palindrome.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > @@ -30,7 +30,7 @@ ### Problem -Given a string `s` which consists of lowercase or uppercase letters, return _the length of the **longest palindrome**_ that can be built with those letters. +Given a string `s` which consists of lowercase or uppercase letters, return *the length of the **longest palindrome*** that can be built with those letters. Letters are **case sensitive**, for example, `"Aa"` is not considered a palindrome here. @@ -50,8 +50,8 @@ Letters are **case sensitive**, for example, `"Aa"` is not considered a palindr #### Constraints -- `1 <= s.length <= 2000` -- `s` consists of lowercase **and/or** uppercase English letters only. +- `1 <= s.length <= 2000` +- `s` consists of lowercase **and/or** uppercase English letters only. ### Thoughts @@ -59,9 +59,10 @@ Letters are **case sensitive**, for example, `"Aa"` is not considered a palindr > This is a #greedy problem. The solution is simple: count the apperances, sort it using -std::greater(), and select all even number, for odd +std::greater(), and select all even number, for odd number `i`: -- if odd numbers has been used: `ans += i - 1` (make it + +- if odd numbers has been used: `ans += i - 1` (make it even) - if not: `ans += i`, and mark odd number used @@ -105,4 +106,4 @@ public: return ans; } }; -``` \ No newline at end of file +``` diff --git a/OJ notes/pages/Leetcode Longest-Substring-Without-Repeating-Characters.md b/OJ notes/pages/Leetcode Longest-Substring-Without-Repeating-Characters.md index c2c8331..77c221e 100644 --- a/OJ notes/pages/Leetcode Longest-Substring-Without-Repeating-Characters.md +++ b/OJ notes/pages/Leetcode Longest-Substring-Without-Repeating-Characters.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Lowest-Common-Ancestor-Of-a-Binary-Search-Tree.md b/OJ notes/pages/Leetcode Lowest-Common-Ancestor-Of-a-Binary-Search-Tree.md index 0c0ba40..ca8be7f 100644 --- a/OJ notes/pages/Leetcode Lowest-Common-Ancestor-Of-a-Binary-Search-Tree.md +++ b/OJ notes/pages/Leetcode Lowest-Common-Ancestor-Of-a-Binary-Search-Tree.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Max-Area-of-Island.md b/OJ notes/pages/Leetcode Max-Area-of-Island.md index 3dfca38..a8370d9 100644 --- a/OJ notes/pages/Leetcode Max-Area-of-Island.md +++ b/OJ notes/pages/Leetcode Max-Area-of-Island.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Maximum-Depth-Of-Binary-Tree.md b/OJ notes/pages/Leetcode Maximum-Depth-Of-Binary-Tree.md index 860f2a6..e0f7eb4 100644 --- a/OJ notes/pages/Leetcode Maximum-Depth-Of-Binary-Tree.md +++ b/OJ notes/pages/Leetcode Maximum-Depth-Of-Binary-Tree.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Maximum-Difference-Between-Increasing-Elements.md b/OJ notes/pages/Leetcode Maximum-Difference-Between-Increasing-Elements.md index d6f930e..6b8eab5 100644 --- a/OJ notes/pages/Leetcode Maximum-Difference-Between-Increasing-Elements.md +++ b/OJ notes/pages/Leetcode Maximum-Difference-Between-Increasing-Elements.md @@ -8,7 +8,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Maxinum-subarray.md b/OJ notes/pages/Leetcode Maxinum-subarray.md index 04c268e..bcd2d29 100644 --- a/OJ notes/pages/Leetcode Maxinum-subarray.md +++ b/OJ notes/pages/Leetcode Maxinum-subarray.md @@ -14,7 +14,7 @@ ##### Difficulty: -#leetcode #coding_problem #difficulty-easy +#leetcode #coding_problem #difficulty_easy ##### Links: diff --git a/OJ notes/pages/Leetcode Merge-Intervals.md b/OJ notes/pages/Leetcode Merge-Intervals.md index 02f9375..bbacfe0 100644 --- a/OJ notes/pages/Leetcode Merge-Intervals.md +++ b/OJ notes/pages/Leetcode Merge-Intervals.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Merge-Sorted-Array.md b/OJ notes/pages/Leetcode Merge-Sorted-Array.md index 77236ee..27a5fdd 100644 --- a/OJ notes/pages/Leetcode Merge-Sorted-Array.md +++ b/OJ notes/pages/Leetcode Merge-Sorted-Array.md @@ -14,7 +14,7 @@ ##### Difficulty: -#leetcode #coding_problem #difficulty-easy +#leetcode #coding_problem #difficulty_easy ##### Related topics: diff --git a/OJ notes/pages/Leetcode Merge-Two-Binary-Trees.md b/OJ notes/pages/Leetcode Merge-Two-Binary-Trees.md index c6e85a9..5c0898f 100644 --- a/OJ notes/pages/Leetcode Merge-Two-Binary-Trees.md +++ b/OJ notes/pages/Leetcode Merge-Two-Binary-Trees.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Merge-Two-Sorted-Lists.md b/OJ notes/pages/Leetcode Merge-Two-Sorted-Lists.md index 959d9d8..f97465c 100644 --- a/OJ notes/pages/Leetcode Merge-Two-Sorted-Lists.md +++ b/OJ notes/pages/Leetcode Merge-Two-Sorted-Lists.md @@ -14,7 +14,7 @@ ##### Difficulty: -#leetcode #coding_problem #difficulty-easy +#leetcode #coding_problem #difficulty_easy ##### Related topics: diff --git a/OJ notes/pages/Leetcode Middle-of-the-Linked-List.md b/OJ notes/pages/Leetcode Middle-of-the-Linked-List.md index a3ec641..1502dc0 100644 --- a/OJ notes/pages/Leetcode Middle-of-the-Linked-List.md +++ b/OJ notes/pages/Leetcode Middle-of-the-Linked-List.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Move-Zeroes.md b/OJ notes/pages/Leetcode Move-Zeroes.md index 7ba34bc..2256776 100644 --- a/OJ notes/pages/Leetcode Move-Zeroes.md +++ b/OJ notes/pages/Leetcode Move-Zeroes.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Next-Greater-Element-I.md b/OJ notes/pages/Leetcode Next-Greater-Element-I.md index b6667d1..f35b09f 100644 --- a/OJ notes/pages/Leetcode Next-Greater-Element-I.md +++ b/OJ notes/pages/Leetcode Next-Greater-Element-I.md @@ -8,7 +8,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Non-Overlapping-Intervals.md b/OJ notes/pages/Leetcode Non-Overlapping-Intervals.md index 1cf391a..951b4a1 100644 --- a/OJ notes/pages/Leetcode Non-Overlapping-Intervals.md +++ b/OJ notes/pages/Leetcode Non-Overlapping-Intervals.md @@ -8,11 +8,11 @@ > > ##### Data structures: > -> #DS #array +> #DS #array > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Number-of-1-Bits.md b/OJ notes/pages/Leetcode Number-of-1-Bits.md index cd99987..8e8a1e4 100644 --- a/OJ notes/pages/Leetcode Number-of-1-Bits.md +++ b/OJ notes/pages/Leetcode Number-of-1-Bits.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Partition-Labels.md b/OJ notes/pages/Leetcode Partition-Labels.md index 6e94b1d..2520e11 100644 --- a/OJ notes/pages/Leetcode Partition-Labels.md +++ b/OJ notes/pages/Leetcode Partition-Labels.md @@ -4,19 +4,19 @@ > ##### Algorithms: > -> #algorithm #greedy +> #algorithm #greedy > > ##### Data structures: > -> #DS #hash_table +> #DS #hash_table > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > -> #leetcode #CS_list_need_practicing +> #leetcode #CS_list_need_practicing > > ##### Revisions: > @@ -62,12 +62,13 @@ A partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits #### Why is it a greedy problem? Consider this situation: + ``` s: ababc partition: abab|c ``` -Note that, for every appearance `ch`, it has be in one +Note that, for every appearance `ch`, it has be in one interval. ``` @@ -77,7 +78,7 @@ ababc | ``` -if the interval for a element `b` is bigger than `a`, +if the interval for a element `b` is bigger than `a`, merge it. ``` @@ -123,4 +124,4 @@ public: return ans; } }; -``` \ No newline at end of file +``` diff --git a/OJ notes/pages/Leetcode Pascal's-Triangle-II.md b/OJ notes/pages/Leetcode Pascal's-Triangle-II.md index 0728fc3..ffd3bc7 100644 --- a/OJ notes/pages/Leetcode Pascal's-Triangle-II.md +++ b/OJ notes/pages/Leetcode Pascal's-Triangle-II.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Pascal's-Triangle.md b/OJ notes/pages/Leetcode Pascal's-Triangle.md index 64a31c7..283ef6d 100644 --- a/OJ notes/pages/Leetcode Pascal's-Triangle.md +++ b/OJ notes/pages/Leetcode Pascal's-Triangle.md @@ -14,7 +14,7 @@ ##### Difficulty: -#leetcode #coding_problem #difficulty-easy +#leetcode #coding_problem #difficulty_easy ##### Related topics: diff --git a/OJ notes/pages/Leetcode Path-Sum.md b/OJ notes/pages/Leetcode Path-Sum.md index 136ca85..4979f6e 100644 --- a/OJ notes/pages/Leetcode Path-Sum.md +++ b/OJ notes/pages/Leetcode Path-Sum.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Permutation-In-String.md b/OJ notes/pages/Leetcode Permutation-In-String.md index e7aeb95..f7e5deb 100644 --- a/OJ notes/pages/Leetcode Permutation-In-String.md +++ b/OJ notes/pages/Leetcode Permutation-In-String.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Permutations.md b/OJ notes/pages/Leetcode Permutations.md index a28342e..61e04ae 100644 --- a/OJ notes/pages/Leetcode Permutations.md +++ b/OJ notes/pages/Leetcode Permutations.md @@ -8,7 +8,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Populating-Next-Right-Pointers-In-Each-Node.md b/OJ notes/pages/Leetcode Populating-Next-Right-Pointers-In-Each-Node.md index 0a084fd..7f8085f 100644 --- a/OJ notes/pages/Leetcode Populating-Next-Right-Pointers-In-Each-Node.md +++ b/OJ notes/pages/Leetcode Populating-Next-Right-Pointers-In-Each-Node.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Power-of-Two.md b/OJ notes/pages/Leetcode Power-of-Two.md index 3b2a3d0..32cc3cc 100644 --- a/OJ notes/pages/Leetcode Power-of-Two.md +++ b/OJ notes/pages/Leetcode Power-of-Two.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Product-of-Array-Except-Self.md b/OJ notes/pages/Leetcode Product-of-Array-Except-Self.md index b8badf6..b033c4f 100644 --- a/OJ notes/pages/Leetcode Product-of-Array-Except-Self.md +++ b/OJ notes/pages/Leetcode Product-of-Array-Except-Self.md @@ -4,7 +4,7 @@ > ##### Algorithms: > -> #algorithm #prefix_sum +> #algorithm #prefix_sum > > ##### Data structures: > @@ -12,11 +12,11 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > -> #leetcode #CS_list_need_understanding +> #leetcode #CS_list_need_understanding > > ##### Revisions: > @@ -25,7 +25,7 @@ ##### Links: - [Link to problem](https://leetcode.com/problems/product-of-array-except-self/) -- [Solution with explanation](https://leetcode.com/problems/product-of-array-except-self/discuss/1597994/C%2B%2BPython-4-Simple-Solutions-w-Explanation-or-Prefix-and-Suffix-product-O(1)-space-approach) +- [Solution with explanation]() --- @@ -51,16 +51,16 @@ You must write an algorithm that runs in `O(n)` time and without using the div #### Constraints -- `2 <= nums.length <= 105` -- `-30 <= nums[i] <= 30` -- The product of any prefix or suffix of `nums` is **guaranteed** to fit in a **32-bit** integer. +- `2 <= nums.length <= 105` +- `-30 <= nums[i] <= 30` +- The product of any prefix or suffix of `nums` is **guaranteed** to fit in a **32-bit** integer. ### Thoughts > [!summary] > This is a variation of #prefix_sum -I thought of using prefix product, a variation of +I thought of using prefix product, a variation of prefix_sum, which perfectly fits the requirement. #### First iteration: @@ -148,6 +148,7 @@ public: ``` First iteration: + ```cpp class Solution { public: @@ -176,4 +177,4 @@ public: return ans; } }; -``` \ No newline at end of file +``` diff --git a/OJ notes/pages/Leetcode Ransom-Note.md b/OJ notes/pages/Leetcode Ransom-Note.md index 80f1ce0..d50ab73 100644 --- a/OJ notes/pages/Leetcode Ransom-Note.md +++ b/OJ notes/pages/Leetcode Ransom-Note.md @@ -14,7 +14,7 @@ ##### Difficulty: -#leetcode #coding_problem #difficulty-easy +#leetcode #coding_problem #difficulty_easy ##### Related topics: diff --git a/OJ notes/pages/Leetcode Remove-Duplicates-From-Sorted-List.md b/OJ notes/pages/Leetcode Remove-Duplicates-From-Sorted-List.md index 0039b3e..8e50e39 100644 --- a/OJ notes/pages/Leetcode Remove-Duplicates-From-Sorted-List.md +++ b/OJ notes/pages/Leetcode Remove-Duplicates-From-Sorted-List.md @@ -8,7 +8,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Remove-Linked-List-Elements.md b/OJ notes/pages/Leetcode Remove-Linked-List-Elements.md index c239544..94993a4 100644 --- a/OJ notes/pages/Leetcode Remove-Linked-List-Elements.md +++ b/OJ notes/pages/Leetcode Remove-Linked-List-Elements.md @@ -10,7 +10,7 @@ ##### Difficulty: -#leetcode #coding_problem #difficulty-easy +#leetcode #coding_problem #difficulty_easy ##### Related topics: diff --git a/OJ notes/pages/Leetcode Remove-Nth-Node-From-End-of-List.md b/OJ notes/pages/Leetcode Remove-Nth-Node-From-End-of-List.md index 86c5b1e..c2ca99b 100644 --- a/OJ notes/pages/Leetcode Remove-Nth-Node-From-End-of-List.md +++ b/OJ notes/pages/Leetcode Remove-Nth-Node-From-End-of-List.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Repeated-DNA-Sequences.md b/OJ notes/pages/Leetcode Repeated-DNA-Sequences.md index c02ca40..b4f0399 100644 --- a/OJ notes/pages/Leetcode Repeated-DNA-Sequences.md +++ b/OJ notes/pages/Leetcode Repeated-DNA-Sequences.md @@ -4,15 +4,15 @@ > ##### Data structures: > -> #DS #hash_table #string +> #DS #hash_table #string > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > -> #leetcode +> #leetcode > > ##### Revisions: > @@ -28,7 +28,7 @@ The **DNA sequence** is composed of a series of nucleotides abbreviated as `'A'`, `'C'`, `'G'`, and `'T'`. -- For example, `"ACGAATTCCG"` is a **DNA sequence**. +- For example, `"ACGAATTCCG"` is a **DNA sequence**. When studying **DNA**, it is useful to identify repeated sequences within the DNA. @@ -57,18 +57,21 @@ The question ask for an answer, and the substrings can overlap. So, using a map is prefered(Why?) Two reasons: -- Easy way to know if a array is a duplicate (set, map can + +- Easy way to know if a array is a duplicate (set, map can suffice.) - Keep information on how many duplicates found, so we only append it to the answer the first time we meet it. One trip-over hole: in the for loop, upper bound should be: + ```cpp for (int i = 0, top = s.size() - 9; i < top; i++) ^^^ ``` Minus 9, because 9 is the extended length for an subarray starting with i. + ``` 1234567890 ^ ^ @@ -100,4 +103,4 @@ public: return ans; } }; -``` \ No newline at end of file +``` diff --git a/OJ notes/pages/Leetcode Reshape-The-Matrix.md b/OJ notes/pages/Leetcode Reshape-The-Matrix.md index 9eea658..aa58998 100644 --- a/OJ notes/pages/Leetcode Reshape-The-Matrix.md +++ b/OJ notes/pages/Leetcode Reshape-The-Matrix.md @@ -10,7 +10,7 @@ ##### Difficulty: -#leetcode #coding_problem #difficulty-easy +#leetcode #coding_problem #difficulty_easy ##### Related topics: diff --git a/OJ notes/pages/Leetcode Reverse-Bits.md b/OJ notes/pages/Leetcode Reverse-Bits.md index d46b1b4..6454f4b 100644 --- a/OJ notes/pages/Leetcode Reverse-Bits.md +++ b/OJ notes/pages/Leetcode Reverse-Bits.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Reverse-Linked-List.md b/OJ notes/pages/Leetcode Reverse-Linked-List.md index 3eef590..d305147 100644 --- a/OJ notes/pages/Leetcode Reverse-Linked-List.md +++ b/OJ notes/pages/Leetcode Reverse-Linked-List.md @@ -14,7 +14,7 @@ ##### Difficulty: -#leetcode #coding_problem #difficulty-medium +#leetcode #coding_problem #difficulty_medium ##### Lists: diff --git a/OJ notes/pages/Leetcode Reverse-String.md b/OJ notes/pages/Leetcode Reverse-String.md index 765c5fa..a79480e 100644 --- a/OJ notes/pages/Leetcode Reverse-String.md +++ b/OJ notes/pages/Leetcode Reverse-String.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Reverse-Words-In-a-String.md b/OJ notes/pages/Leetcode Reverse-Words-In-a-String.md index 2001d8e..1584f4d 100644 --- a/OJ notes/pages/Leetcode Reverse-Words-In-a-String.md +++ b/OJ notes/pages/Leetcode Reverse-Words-In-a-String.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Rotate-Array.md b/OJ notes/pages/Leetcode Rotate-Array.md index 7ccd9af..c7e2aa8 100644 --- a/OJ notes/pages/Leetcode Rotate-Array.md +++ b/OJ notes/pages/Leetcode Rotate-Array.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Rotate-Image.md b/OJ notes/pages/Leetcode Rotate-Image.md index 7e18cac..69672af 100644 --- a/OJ notes/pages/Leetcode Rotate-Image.md +++ b/OJ notes/pages/Leetcode Rotate-Image.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Rotting-Oranges.md b/OJ notes/pages/Leetcode Rotting-Oranges.md index f8e1b34..0ca3dc9 100644 --- a/OJ notes/pages/Leetcode Rotting-Oranges.md +++ b/OJ notes/pages/Leetcode Rotting-Oranges.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Search-A-2D-Matrix-II.md b/OJ notes/pages/Leetcode Search-A-2D-Matrix-II.md index 3cb7cd0..a0c0710 100644 --- a/OJ notes/pages/Leetcode Search-A-2D-Matrix-II.md +++ b/OJ notes/pages/Leetcode Search-A-2D-Matrix-II.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Search-In-a-Binary-Tree.md b/OJ notes/pages/Leetcode Search-In-a-Binary-Tree.md index ae1630b..089c16a 100644 --- a/OJ notes/pages/Leetcode Search-In-a-Binary-Tree.md +++ b/OJ notes/pages/Leetcode Search-In-a-Binary-Tree.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Search-Insert-Position.md b/OJ notes/pages/Leetcode Search-Insert-Position.md index 8bad8e8..90b8484 100644 --- a/OJ notes/pages/Leetcode Search-Insert-Position.md +++ b/OJ notes/pages/Leetcode Search-Insert-Position.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Search-a-2D-Matrix.md b/OJ notes/pages/Leetcode Search-a-2D-Matrix.md index 0d51006..377b37a 100644 --- a/OJ notes/pages/Leetcode Search-a-2D-Matrix.md +++ b/OJ notes/pages/Leetcode Search-a-2D-Matrix.md @@ -14,7 +14,7 @@ ##### Difficulty: -#leetcode #coding_problem #difficulty-easy +#leetcode #coding_problem #difficulty_easy ##### Related topics: diff --git a/OJ notes/pages/Leetcode Single-Number.md b/OJ notes/pages/Leetcode Single-Number.md index 59b924a..8378a24 100644 --- a/OJ notes/pages/Leetcode Single-Number.md +++ b/OJ notes/pages/Leetcode Single-Number.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Sort-Colors.md b/OJ notes/pages/Leetcode Sort-Colors.md index f0ff203..5437892 100644 --- a/OJ notes/pages/Leetcode Sort-Colors.md +++ b/OJ notes/pages/Leetcode Sort-Colors.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Squares-of-a-Sorted-Array.md b/OJ notes/pages/Leetcode Squares-of-a-Sorted-Array.md index 9b6c957..931f2d6 100644 --- a/OJ notes/pages/Leetcode Squares-of-a-Sorted-Array.md +++ b/OJ notes/pages/Leetcode Squares-of-a-Sorted-Array.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Subarray-Sum-Equals-K.md b/OJ notes/pages/Leetcode Subarray-Sum-Equals-K.md index 3093607..54fa3ca 100644 --- a/OJ notes/pages/Leetcode Subarray-Sum-Equals-K.md +++ b/OJ notes/pages/Leetcode Subarray-Sum-Equals-K.md @@ -4,19 +4,19 @@ > ##### Algorithms: > -> #algorithm #hash_table +> #algorithm #hash_table > > ##### Data structures: > -> #DS #array +> #DS #array > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > -> #leetcode #CS_list_need_practicing +> #leetcode #CS_list_need_practicing > > ##### Revisions: > @@ -49,28 +49,28 @@ A subarray is a contiguous **non-empty** sequence of elements within an array. #### Constraints -- `1 <= nums.length <= 2 * 104` -- `-1000 <= nums[i] <= 1000` -- `-107 <= k <= 107` +- `1 <= nums.length <= 2 * 104` +- `-1000 <= nums[i] <= 1000` +- `-107 <= k <= 107` ### Thoughts > [!summary] -> This can be solved using #prefix_sum and #hash_table +> This can be solved using #prefix_sum and #hash_table -> I over-complicated the solution by adding stuff like +> I over-complicated the solution by adding stuff like > sorting, but it turn out to be not so difficult. > [!tip] -> Tried using sliding window, but it doesn't work because of +> Tried using sliding window, but it doesn't work because of > negative numbers. -This one is harder to understand, making it a medium +This one is harder to understand, making it a medium difficulty problem. The intuition is using prefix to count the subarray sum, and -use hashmaps to count the **number of subarray sums**. This -takes care of **negative numbers** which is not solvable +use hashmaps to count the **number of subarray sums**. This +takes care of **negative numbers** which is not solvable using sliding windows. We step one cell at a time, and try to ask ourselves: @@ -111,6 +111,7 @@ public: ``` TLE, brute force + ```cpp class Solution { public: diff --git a/OJ notes/pages/Leetcode Subsets.md b/OJ notes/pages/Leetcode Subsets.md index cb7670d..6a2be65 100644 --- a/OJ notes/pages/Leetcode Subsets.md +++ b/OJ notes/pages/Leetcode Subsets.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Symmetric-Tree.md b/OJ notes/pages/Leetcode Symmetric-Tree.md index cf8bd62..6a802f8 100644 --- a/OJ notes/pages/Leetcode Symmetric-Tree.md +++ b/OJ notes/pages/Leetcode Symmetric-Tree.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Triangle.md b/OJ notes/pages/Leetcode Triangle.md index 6c8483f..c407c3a 100644 --- a/OJ notes/pages/Leetcode Triangle.md +++ b/OJ notes/pages/Leetcode Triangle.md @@ -8,7 +8,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Two-Sum-II-Input-Array-Is-Sorted.md b/OJ notes/pages/Leetcode Two-Sum-II-Input-Array-Is-Sorted.md index 8f10739..5831f1c 100644 --- a/OJ notes/pages/Leetcode Two-Sum-II-Input-Array-Is-Sorted.md +++ b/OJ notes/pages/Leetcode Two-Sum-II-Input-Array-Is-Sorted.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Two-Sum-IV-Input-Is-a-BST.md b/OJ notes/pages/Leetcode Two-Sum-IV-Input-Is-a-BST.md index 67c8367..993190d 100644 --- a/OJ notes/pages/Leetcode Two-Sum-IV-Input-Is-a-BST.md +++ b/OJ notes/pages/Leetcode Two-Sum-IV-Input-Is-a-BST.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Two-Sum.md b/OJ notes/pages/Leetcode Two-Sum.md index 6167d35..e40e68c 100644 --- a/OJ notes/pages/Leetcode Two-Sum.md +++ b/OJ notes/pages/Leetcode Two-Sum.md @@ -14,7 +14,7 @@ ##### Difficulty: -#coding_problem #leetcode #difficulty-easy +#coding_problem #leetcode #difficulty_easy ##### Related topics: diff --git a/OJ notes/pages/Leetcode Valid-Anagram.md b/OJ notes/pages/Leetcode Valid-Anagram.md index 870c379..36b5c08 100644 --- a/OJ notes/pages/Leetcode Valid-Anagram.md +++ b/OJ notes/pages/Leetcode Valid-Anagram.md @@ -14,7 +14,7 @@ ##### Difficulty: -#leetcode #coding_problem #difficulty-easy +#leetcode #coding_problem #difficulty_easy ##### Related topics: diff --git a/OJ notes/pages/Leetcode Valid-Parentheses.md b/OJ notes/pages/Leetcode Valid-Parentheses.md index 7f0e684..ffcaf7f 100644 --- a/OJ notes/pages/Leetcode Valid-Parentheses.md +++ b/OJ notes/pages/Leetcode Valid-Parentheses.md @@ -8,7 +8,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Valid-Sudoku.md b/OJ notes/pages/Leetcode Valid-Sudoku.md index 17fb850..d8d3813 100644 --- a/OJ notes/pages/Leetcode Valid-Sudoku.md +++ b/OJ notes/pages/Leetcode Valid-Sudoku.md @@ -10,7 +10,7 @@ ##### Difficulty: -#leetcode #coding_problem #difficulty-easy +#leetcode #coding_problem #difficulty_easy ##### Related topics: diff --git a/OJ notes/pages/Leetcode Validate-Binary-Search-Tree.md b/OJ notes/pages/Leetcode Validate-Binary-Search-Tree.md index 0834fe2..b1e1f5d 100644 --- a/OJ notes/pages/Leetcode Validate-Binary-Search-Tree.md +++ b/OJ notes/pages/Leetcode Validate-Binary-Search-Tree.md @@ -12,7 +12,7 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-medium +> #coding_problem #difficulty_medium > > ##### Additional tags: > diff --git a/OJ notes/pages/Leetcode Word-Pattern.md b/OJ notes/pages/Leetcode Word-Pattern.md index 92e53cd..6f991ac 100644 --- a/OJ notes/pages/Leetcode Word-Pattern.md +++ b/OJ notes/pages/Leetcode Word-Pattern.md @@ -8,11 +8,11 @@ > > ##### Difficulty: > -> #coding_problem #difficulty-easy +> #coding_problem #difficulty_easy > > ##### Additional tags: > -> #leetcode +> #leetcode > > ##### Revisions: > @@ -49,27 +49,28 @@ Here **follow** means a full match, such that there is a bijection between a let #### Constraints -- `1 <= pattern.length <= 300` -- `pattern` contains only lower-case English letters. -- `1 <= s.length <= 3000` -- `s` contains only lowercase English letters and spaces `' '`. -- `s` **does not contain** any leading or trailing spaces. -- All the words in `s` are separated by a **single space**. +- `1 <= pattern.length <= 300` +- `pattern` contains only lower-case English letters. +- `1 <= s.length <= 3000` +- `s` contains only lowercase English letters and spaces `' '`. +- `s` **does not contain** any leading or trailing spaces. +- All the words in `s` are separated by a **single space**. ### Thoughts > [!summary] > This is a #string operation problem. -The main part is using two hash tables, to check for +The main part is using two hash tables, to check for mismatches, and using `istringstream` to read from string -Two hash tables: +Two hash tables: + - One is used to check for s has one and only bound word -- The other is used to check that the word is only stored +- The other is used to check that the word is only stored once -Using one hash table is one way, which makes one way +Using one hash table is one way, which makes one way unchecked. ### Solution @@ -105,4 +106,4 @@ public: } } }; -``` \ No newline at end of file +``` diff --git a/OJ notes/pages/Two pointers approach.md b/OJ notes/pages/Two pointers approach.md index 0a285d9..04ed07f 100644 --- a/OJ notes/pages/Two pointers approach.md +++ b/OJ notes/pages/Two pointers approach.md @@ -41,4 +41,4 @@ By using two pointers, to in place modify array elements. Refer to [this link](https://leetcode.com/problems/subarray-sum-equals-k/discuss/301242/General-summary-of-what-kind-of-problem-can-cannot-solved-by-Two-Pointers) -#TODO: complete this section \ No newline at end of file +#TODO: complete this section diff --git a/OJ notes/pages/cpp_Range_based_for_loop.md b/OJ notes/pages/cpp_Range_based_for_loop.md index 2173963..62e90c5 100644 --- a/OJ notes/pages/cpp_Range_based_for_loop.md +++ b/OJ notes/pages/cpp_Range_based_for_loop.md @@ -10,7 +10,7 @@ ##### Difficulty: -#CS_analysis #difficulty-easy +#CS_analysis #difficulty_easy ##### Related problems: diff --git a/OJ notes/pages/cpp_std_multiset.md b/OJ notes/pages/cpp_std_multiset.md index 67ef279..fcb4cc4 100644 --- a/OJ notes/pages/cpp_std_multiset.md +++ b/OJ notes/pages/cpp_std_multiset.md @@ -10,7 +10,7 @@ ##### Difficulty: -#CS_analysis #difficulty-easy +#CS_analysis #difficulty_easy ##### Related problems: diff --git a/OJ notes/pages/cpp_std_sort.md b/OJ notes/pages/cpp_std_sort.md index 7865439..c2f58e8 100644 --- a/OJ notes/pages/cpp_std_sort.md +++ b/OJ notes/pages/cpp_std_sort.md @@ -10,7 +10,7 @@ ##### Difficulty: -#CS_analysis #difficulty-easy +#CS_analysis #difficulty_easy ##### Related problems: diff --git a/OJ notes/pages/cpp_std_unordered_map.md b/OJ notes/pages/cpp_std_unordered_map.md index 5106eae..1d7814c 100644 --- a/OJ notes/pages/cpp_std_unordered_map.md +++ b/OJ notes/pages/cpp_std_unordered_map.md @@ -10,7 +10,7 @@ ##### Difficulty: -#CS_analysis #difficulty-easy +#CS_analysis #difficulty_easy ##### Related problems: