vault backup: 2022-09-06 20:22:48
This commit is contained in:
parent
99e9f02118
commit
8f8ff15ddb
2
.obsidian/appearance.json
vendored
2
.obsidian/appearance.json
vendored
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"theme": "moonstone",
|
||||
"theme": "obsidian",
|
||||
"translucency": true,
|
||||
"cssTheme": "Prism",
|
||||
"interfaceFontFamily": "IBM Plex Sans",
|
||||
|
|
14
.obsidian/graph.json
vendored
14
.obsidian/graph.json
vendored
|
@ -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
|
||||
}
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#CS_analysis #difficulty-easy
|
||||
#CS_analysis #difficulty_easy
|
||||
|
||||
##### Related problems:
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #CS_analysis #difficulty-easy
|
||||
> #CS_analysis #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #CS_analysis #difficulty-
|
||||
> #CS_analysis #difficulty_
|
||||
>
|
||||
> ##### Additional tags:
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#CS_analysis #difficulty-easy
|
||||
#CS_analysis #difficulty_easy
|
||||
|
||||
##### Related problems:
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#CS_analysis #difficulty-easy
|
||||
#CS_analysis #difficulty_easy
|
||||
|
||||
##### Time complexity:
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
@ -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
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#leetcode #coding_problem #difficulty-easy
|
||||
#leetcode #coding_problem #difficulty_easy
|
||||
|
||||
##### Related topics:
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-
|
||||
> #coding_problem #difficulty_
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#leetcode #coding_problem #difficulty-easy
|
||||
#leetcode #coding_problem #difficulty_easy
|
||||
|
||||
##### Related topics:
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
@ -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
|
||||
|
||||
|
@ -68,6 +68,7 @@ An **Anagram** is a word or phrase formed by rearranging the letters of a differ
|
|||
|
||||
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<int, 26> ana = {};
|
||||
> ```
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
@ -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
|
||||
|
||||
|
@ -68,17 +68,17 @@ 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`
|
||||
to `small`
|
||||
|
||||
> `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 ?
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#leetcode #coding_problem #difficulty-easy
|
||||
#leetcode #coding_problem #difficulty_easy
|
||||
|
||||
##### Related topics:
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#leetcode #coding_problem #difficulty-easy
|
||||
#leetcode #coding_problem #difficulty_easy
|
||||
|
||||
##### Related topics:
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -61,6 +61,7 @@ Letters are **case sensitive**, for example, `"Aa"` is not considered a palindr
|
|||
The solution is simple: count the apperances, sort it using
|
||||
std::greater<int>(), and select all even number, for odd
|
||||
number `i`:
|
||||
|
||||
- if odd numbers has been used: `ans += i - 1` (make it
|
||||
even)
|
||||
- if not: `ans += i`, and mark odd number used
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#leetcode #coding_problem #difficulty-easy
|
||||
#leetcode #coding_problem #difficulty_easy
|
||||
|
||||
##### Links:
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#leetcode #coding_problem #difficulty-easy
|
||||
#leetcode #coding_problem #difficulty_easy
|
||||
|
||||
##### Related topics:
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#leetcode #coding_problem #difficulty-easy
|
||||
#leetcode #coding_problem #difficulty_easy
|
||||
|
||||
##### Related topics:
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
@ -62,6 +62,7 @@ A partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits
|
|||
#### Why is it a greedy problem?
|
||||
|
||||
Consider this situation:
|
||||
|
||||
```
|
||||
s: ababc
|
||||
partition: abab|c
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#leetcode #coding_problem #difficulty-easy
|
||||
#leetcode #coding_problem #difficulty_easy
|
||||
|
||||
##### Related topics:
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
@ -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](<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>)
|
||||
|
||||
---
|
||||
|
||||
|
@ -51,9 +51,9 @@ 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
|
||||
|
||||
|
@ -148,6 +148,7 @@ public:
|
|||
```
|
||||
|
||||
First iteration:
|
||||
|
||||
```cpp
|
||||
class Solution {
|
||||
public:
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#leetcode #coding_problem #difficulty-easy
|
||||
#leetcode #coding_problem #difficulty_easy
|
||||
|
||||
##### Related topics:
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#leetcode #coding_problem #difficulty-easy
|
||||
#leetcode #coding_problem #difficulty_easy
|
||||
|
||||
##### Related topics:
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
@ -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
|
||||
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
|
||||
^ ^
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#leetcode #coding_problem #difficulty-easy
|
||||
#leetcode #coding_problem #difficulty_easy
|
||||
|
||||
##### Related topics:
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#leetcode #coding_problem #difficulty-medium
|
||||
#leetcode #coding_problem #difficulty_medium
|
||||
|
||||
##### Lists:
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#leetcode #coding_problem #difficulty-easy
|
||||
#leetcode #coding_problem #difficulty_easy
|
||||
|
||||
##### Related topics:
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
@ -49,9 +49,9 @@ 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
|
||||
|
||||
|
@ -111,6 +111,7 @@ public:
|
|||
```
|
||||
|
||||
TLE, brute force
|
||||
|
||||
```cpp
|
||||
class Solution {
|
||||
public:
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#coding_problem #leetcode #difficulty-easy
|
||||
#coding_problem #leetcode #difficulty_easy
|
||||
|
||||
##### Related topics:
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#leetcode #coding_problem #difficulty-easy
|
||||
#leetcode #coding_problem #difficulty_easy
|
||||
|
||||
##### Related topics:
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#leetcode #coding_problem #difficulty-easy
|
||||
#leetcode #coding_problem #difficulty_easy
|
||||
|
||||
##### Related topics:
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-medium
|
||||
> #coding_problem #difficulty_medium
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
>
|
||||
> ##### Difficulty:
|
||||
>
|
||||
> #coding_problem #difficulty-easy
|
||||
> #coding_problem #difficulty_easy
|
||||
>
|
||||
> ##### Additional tags:
|
||||
>
|
||||
|
@ -49,12 +49,12 @@ 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
|
||||
|
||||
|
@ -65,6 +65,7 @@ The main part is using two hash tables, to check for
|
|||
mismatches, and using `istringstream` to read from string
|
||||
|
||||
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
|
||||
once
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#CS_analysis #difficulty-easy
|
||||
#CS_analysis #difficulty_easy
|
||||
|
||||
##### Related problems:
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#CS_analysis #difficulty-easy
|
||||
#CS_analysis #difficulty_easy
|
||||
|
||||
##### Related problems:
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#CS_analysis #difficulty-easy
|
||||
#CS_analysis #difficulty_easy
|
||||
|
||||
##### Related problems:
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
##### Difficulty:
|
||||
|
||||
#CS_analysis #difficulty-easy
|
||||
#CS_analysis #difficulty_easy
|
||||
|
||||
##### Related problems:
|
||||
|
||||
|
|
Loading…
Reference in a new issue