diff --git a/solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/README.md b/solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/README.md index 18a09a5ca7acf..8233faf7d68d6 100644 --- a/solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/README.md +++ b/solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/README.md @@ -165,7 +165,7 @@ func longestSubarray(nums []int, limit int) (ans int) { ### **TypeScript** -````ts +```ts function longestSubarray(nums: number[], limit: number): number { const ts = new TreapMultiSet(); let ans = 0; @@ -281,37 +281,6 @@ class TreapMultiSet implements ITreapMultiSet { private readonly leftBound: T; private readonly rightBound: T; - /** - * - * @param compareFn A compare function which returns boolean or number - * @param leftBound defalut value is `-Infinity` - * @param rightBound defalut value is `Infinity` - * @description - * create a `MultiSet`, compare elements using `compareFn`, which is increasing order by default. - * @example - * ```ts - * interface Person { - name: string - age: number - } - - const leftBound = { - name: 'Alice', - age: -Infinity, - } - - const rightBound = { - name: 'Bob', - age: Infinity, - } - - const sortedList = new TreapMultiSet( - (a: Person, b: Person) => a.age - b.age, - leftBound, - rightBound - ) - * ``` - */ constructor(compareFn?: CompareFunction); constructor(compareFn: CompareFunction, leftBound: T, rightBound: T); constructor( @@ -828,7 +797,7 @@ class TreapMultiSet implements ITreapMultiSet { yield* this.reverseInOrder(root.left); } } -```` +``` ### **...** diff --git a/solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/README_EN.md b/solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/README_EN.md index 02a25f7d2c509..cccd86cf2450f 100644 --- a/solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/README_EN.md +++ b/solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/README_EN.md @@ -150,7 +150,7 @@ func longestSubarray(nums []int, limit int) (ans int) { ### **TypeScript** -````ts +```ts function longestSubarray(nums: number[], limit: number): number { const ts = new TreapMultiSet(); let ans = 0; @@ -266,37 +266,6 @@ class TreapMultiSet implements ITreapMultiSet { private readonly leftBound: T; private readonly rightBound: T; - /** - * - * @param compareFn A compare function which returns boolean or number - * @param leftBound defalut value is `-Infinity` - * @param rightBound defalut value is `Infinity` - * @description - * create a `MultiSet`, compare elements using `compareFn`, which is increasing order by default. - * @example - * ```ts - * interface Person { - name: string - age: number - } - - const leftBound = { - name: 'Alice', - age: -Infinity, - } - - const rightBound = { - name: 'Bob', - age: Infinity, - } - - const sortedList = new TreapMultiSet( - (a: Person, b: Person) => a.age - b.age, - leftBound, - rightBound - ) - * ``` - */ constructor(compareFn?: CompareFunction); constructor(compareFn: CompareFunction, leftBound: T, rightBound: T); constructor( @@ -813,7 +782,7 @@ class TreapMultiSet implements ITreapMultiSet { yield* this.reverseInOrder(root.left); } } -```` +``` ### **...** diff --git a/solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/Solution.ts b/solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/Solution.ts index d800e6e9cbeea..e334426da3ffb 100644 --- a/solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/Solution.ts +++ b/solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/Solution.ts @@ -113,37 +113,6 @@ class TreapMultiSet implements ITreapMultiSet { private readonly leftBound: T; private readonly rightBound: T; - /** - * - * @param compareFn A compare function which returns boolean or number - * @param leftBound defalut value is `-Infinity` - * @param rightBound defalut value is `Infinity` - * @description - * create a `MultiSet`, compare elements using `compareFn`, which is increasing order by default. - * @example - * ```ts - * interface Person { - name: string - age: number - } - - const leftBound = { - name: 'Alice', - age: -Infinity, - } - - const rightBound = { - name: 'Bob', - age: Infinity, - } - - const sortedList = new TreapMultiSet( - (a: Person, b: Person) => a.age - b.age, - leftBound, - rightBound - ) - * ``` - */ constructor(compareFn?: CompareFunction); constructor(compareFn: CompareFunction, leftBound: T, rightBound: T); constructor( diff --git a/solution/2000-2099/2085.Count Common Words With One Occurrence/README.md b/solution/2000-2099/2085.Count Common Words With One Occurrence/README.md index 87fefb3279a72..6803e9dc5b365 100644 --- a/solution/2000-2099/2085.Count Common Words With One Occurrence/README.md +++ b/solution/2000-2099/2085.Count Common Words With One Occurrence/README.md @@ -53,9 +53,9 @@ -**方法一:哈希表** +**方法一:哈希表计数** -我们可以用两个哈希表分别统计两个字符串数组中每个字符串出现的次数,然后遍历其中一个哈希表,如果某个字符串在另一个哈希表中出现了一次,且在当前哈希表中也出现了一次,则答案加一。 +我们可以用两个哈希表 $cnt1$ 和 $cnt2$ 分别统计两个字符串数组中每个字符串出现的次数,然后遍历其中一个哈希表,如果某个字符串在另一个哈希表中出现了一次,且在当前哈希表中也出现了一次,则答案加一。 时间复杂度 $O(n + m)$,空间复杂度 $O(n + m)$。其中 $n$ 和 $m$ 分别是两个字符串数组的长度。 @@ -70,7 +70,7 @@ class Solution: def countWords(self, words1: List[str], words2: List[str]) -> int: cnt1 = Counter(words1) cnt2 = Counter(words2) - return sum(cnt2[k] == 1 for k, v in cnt1.items() if v == 1) + return sum(v == 1 and cnt2[w] == 1 for w, v in cnt1.items()) ``` ### **Java** @@ -80,24 +80,22 @@ class Solution: ```java class Solution { public int countWords(String[] words1, String[] words2) { - Map cnt1 = count(words1); - Map cnt2 = count(words2); + Map cnt1 = new HashMap<>(); + Map cnt2 = new HashMap<>(); + for (var w : words1) { + cnt1.merge(w, 1, Integer::sum); + } + for (var w : words2) { + cnt2.merge(w, 1, Integer::sum); + } int ans = 0; - for (String w : words1) { - if (cnt1.getOrDefault(w, 0) == 1 && cnt2.getOrDefault(w, 0) == 1) { + for (var e : cnt1.entrySet()) { + if (e.getValue() == 1 && cnt2.getOrDefault(e.getKey(), 0) == 1) { ++ans; } } return ans; } - - private Map count(String[] words) { - Map cnt = new HashMap<>(); - for (String w : words) { - cnt.put(w, cnt.getOrDefault(w, 0) + 1); - } - return cnt; - } } ``` @@ -109,10 +107,16 @@ public: int countWords(vector& words1, vector& words2) { unordered_map cnt1; unordered_map cnt2; - for (auto& w : words1) cnt1[w]++; - for (auto& w : words2) cnt2[w]++; + for (auto& w : words1) { + ++cnt1[w]; + } + for (auto& w : words2) { + ++cnt2[w]; + } int ans = 0; - for (auto& w : words1) ans += (cnt1[w] == 1 && cnt2[w] == 1); + for (auto& [w, v] : cnt1) { + ans += v == 1 && cnt2[w] == 1; + } return ans; } }; @@ -121,7 +125,7 @@ public: ### **Go** ```go -func countWords(words1 []string, words2 []string) int { +func countWords(words1 []string, words2 []string) (ans int) { cnt1 := map[string]int{} cnt2 := map[string]int{} for _, w := range words1 { @@ -130,13 +134,34 @@ func countWords(words1 []string, words2 []string) int { for _, w := range words2 { cnt2[w]++ } - ans := 0 - for _, w := range words1 { - if cnt1[w] == 1 && cnt2[w] == 1 { + for w, v := range cnt1 { + if v == 1 && cnt2[w] == 1 { ans++ } } - return ans + return +} +``` + +### **TypeScript** + +```ts +function countWords(words1: string[], words2: string[]): number { + const cnt1 = new Map(); + const cnt2 = new Map(); + for (const w of words1) { + cnt1.set(w, (cnt1.get(w) ?? 0) + 1); + } + for (const w of words2) { + cnt2.set(w, (cnt2.get(w) ?? 0) + 1); + } + let ans = 0; + for (const [w, v] of cnt1) { + if (v === 1 && cnt2.get(w) === 1) { + ++ans; + } + } + return ans; } ``` diff --git a/solution/2000-2099/2085.Count Common Words With One Occurrence/README_EN.md b/solution/2000-2099/2085.Count Common Words With One Occurrence/README_EN.md index 8c00227000d18..010e07460e322 100644 --- a/solution/2000-2099/2085.Count Common Words With One Occurrence/README_EN.md +++ b/solution/2000-2099/2085.Count Common Words With One Occurrence/README_EN.md @@ -47,6 +47,12 @@ Thus, there are 2 strings that appear exactly once in each of the two arrays. ## Solutions +**Solution 1: Hash Table + Counting** + +We can use two hash tables, $cnt1$ and $cnt2$, to count the occurrences of each string in the two string arrays respectively. Then, we traverse one of the hash tables. If a string appears once in the other hash table and also appears once in the current hash table, we increment the answer by one. + +The time complexity is $O(n + m)$, and the space complexity is $O(n + m)$. Where $n$ and $m$ are the lengths of the two string arrays respectively. + ### **Python3** @@ -56,7 +62,7 @@ class Solution: def countWords(self, words1: List[str], words2: List[str]) -> int: cnt1 = Counter(words1) cnt2 = Counter(words2) - return sum(cnt2[k] == 1 for k, v in cnt1.items() if v == 1) + return sum(v == 1 and cnt2[w] == 1 for w, v in cnt1.items()) ``` ### **Java** @@ -64,24 +70,22 @@ class Solution: ```java class Solution { public int countWords(String[] words1, String[] words2) { - Map cnt1 = count(words1); - Map cnt2 = count(words2); + Map cnt1 = new HashMap<>(); + Map cnt2 = new HashMap<>(); + for (var w : words1) { + cnt1.merge(w, 1, Integer::sum); + } + for (var w : words2) { + cnt2.merge(w, 1, Integer::sum); + } int ans = 0; - for (String w : words1) { - if (cnt1.getOrDefault(w, 0) == 1 && cnt2.getOrDefault(w, 0) == 1) { + for (var e : cnt1.entrySet()) { + if (e.getValue() == 1 && cnt2.getOrDefault(e.getKey(), 0) == 1) { ++ans; } } return ans; } - - private Map count(String[] words) { - Map cnt = new HashMap<>(); - for (String w : words) { - cnt.put(w, cnt.getOrDefault(w, 0) + 1); - } - return cnt; - } } ``` @@ -93,10 +97,16 @@ public: int countWords(vector& words1, vector& words2) { unordered_map cnt1; unordered_map cnt2; - for (auto& w : words1) cnt1[w]++; - for (auto& w : words2) cnt2[w]++; + for (auto& w : words1) { + ++cnt1[w]; + } + for (auto& w : words2) { + ++cnt2[w]; + } int ans = 0; - for (auto& w : words1) ans += (cnt1[w] == 1 && cnt2[w] == 1); + for (auto& [w, v] : cnt1) { + ans += v == 1 && cnt2[w] == 1; + } return ans; } }; @@ -105,7 +115,7 @@ public: ### **Go** ```go -func countWords(words1 []string, words2 []string) int { +func countWords(words1 []string, words2 []string) (ans int) { cnt1 := map[string]int{} cnt2 := map[string]int{} for _, w := range words1 { @@ -114,13 +124,34 @@ func countWords(words1 []string, words2 []string) int { for _, w := range words2 { cnt2[w]++ } - ans := 0 - for _, w := range words1 { - if cnt1[w] == 1 && cnt2[w] == 1 { + for w, v := range cnt1 { + if v == 1 && cnt2[w] == 1 { ans++ } } - return ans + return +} +``` + +### **TypeScript** + +```ts +function countWords(words1: string[], words2: string[]): number { + const cnt1 = new Map(); + const cnt2 = new Map(); + for (const w of words1) { + cnt1.set(w, (cnt1.get(w) ?? 0) + 1); + } + for (const w of words2) { + cnt2.set(w, (cnt2.get(w) ?? 0) + 1); + } + let ans = 0; + for (const [w, v] of cnt1) { + if (v === 1 && cnt2.get(w) === 1) { + ++ans; + } + } + return ans; } ``` diff --git a/solution/2000-2099/2085.Count Common Words With One Occurrence/Solution.cpp b/solution/2000-2099/2085.Count Common Words With One Occurrence/Solution.cpp index 80f99b6d1e348..a8f931c5a47e9 100644 --- a/solution/2000-2099/2085.Count Common Words With One Occurrence/Solution.cpp +++ b/solution/2000-2099/2085.Count Common Words With One Occurrence/Solution.cpp @@ -3,10 +3,16 @@ class Solution { int countWords(vector& words1, vector& words2) { unordered_map cnt1; unordered_map cnt2; - for (auto& w : words1) cnt1[w]++; - for (auto& w : words2) cnt2[w]++; + for (auto& w : words1) { + ++cnt1[w]; + } + for (auto& w : words2) { + ++cnt2[w]; + } int ans = 0; - for (auto& w : words1) ans += (cnt1[w] == 1 && cnt2[w] == 1); + for (auto& [w, v] : cnt1) { + ans += v == 1 && cnt2[w] == 1; + } return ans; } }; \ No newline at end of file diff --git a/solution/2000-2099/2085.Count Common Words With One Occurrence/Solution.go b/solution/2000-2099/2085.Count Common Words With One Occurrence/Solution.go index 4944125081a4a..abe50fe466a8a 100644 --- a/solution/2000-2099/2085.Count Common Words With One Occurrence/Solution.go +++ b/solution/2000-2099/2085.Count Common Words With One Occurrence/Solution.go @@ -1,4 +1,4 @@ -func countWords(words1 []string, words2 []string) int { +func countWords(words1 []string, words2 []string) (ans int) { cnt1 := map[string]int{} cnt2 := map[string]int{} for _, w := range words1 { @@ -7,11 +7,10 @@ func countWords(words1 []string, words2 []string) int { for _, w := range words2 { cnt2[w]++ } - ans := 0 - for _, w := range words1 { - if cnt1[w] == 1 && cnt2[w] == 1 { + for w, v := range cnt1 { + if v == 1 && cnt2[w] == 1 { ans++ } } - return ans + return } \ No newline at end of file diff --git a/solution/2000-2099/2085.Count Common Words With One Occurrence/Solution.java b/solution/2000-2099/2085.Count Common Words With One Occurrence/Solution.java index 8b2557df393af..5da266de10127 100644 --- a/solution/2000-2099/2085.Count Common Words With One Occurrence/Solution.java +++ b/solution/2000-2099/2085.Count Common Words With One Occurrence/Solution.java @@ -1,21 +1,19 @@ class Solution { public int countWords(String[] words1, String[] words2) { - Map cnt1 = count(words1); - Map cnt2 = count(words2); + Map cnt1 = new HashMap<>(); + Map cnt2 = new HashMap<>(); + for (var w : words1) { + cnt1.merge(w, 1, Integer::sum); + } + for (var w : words2) { + cnt2.merge(w, 1, Integer::sum); + } int ans = 0; - for (String w : words1) { - if (cnt1.getOrDefault(w, 0) == 1 && cnt2.getOrDefault(w, 0) == 1) { + for (var e : cnt1.entrySet()) { + if (e.getValue() == 1 && cnt2.getOrDefault(e.getKey(), 0) == 1) { ++ans; } } return ans; } - - private Map count(String[] words) { - Map cnt = new HashMap<>(); - for (String w : words) { - cnt.put(w, cnt.getOrDefault(w, 0) + 1); - } - return cnt; - } } \ No newline at end of file diff --git a/solution/2000-2099/2085.Count Common Words With One Occurrence/Solution.py b/solution/2000-2099/2085.Count Common Words With One Occurrence/Solution.py index 4fe15942faa54..49f27a8e282c5 100644 --- a/solution/2000-2099/2085.Count Common Words With One Occurrence/Solution.py +++ b/solution/2000-2099/2085.Count Common Words With One Occurrence/Solution.py @@ -2,4 +2,4 @@ class Solution: def countWords(self, words1: List[str], words2: List[str]) -> int: cnt1 = Counter(words1) cnt2 = Counter(words2) - return sum(cnt2[k] == 1 for k, v in cnt1.items() if v == 1) + return sum(v == 1 and cnt2[w] == 1 for w, v in cnt1.items()) diff --git a/solution/2000-2099/2085.Count Common Words With One Occurrence/Solution.ts b/solution/2000-2099/2085.Count Common Words With One Occurrence/Solution.ts new file mode 100644 index 0000000000000..a7c19ca0e3899 --- /dev/null +++ b/solution/2000-2099/2085.Count Common Words With One Occurrence/Solution.ts @@ -0,0 +1,17 @@ +function countWords(words1: string[], words2: string[]): number { + const cnt1 = new Map(); + const cnt2 = new Map(); + for (const w of words1) { + cnt1.set(w, (cnt1.get(w) ?? 0) + 1); + } + for (const w of words2) { + cnt2.set(w, (cnt2.get(w) ?? 0) + 1); + } + let ans = 0; + for (const [w, v] of cnt1) { + if (v === 1 && cnt2.get(w) === 1) { + ++ans; + } + } + return ans; +} diff --git a/solution/2600-2699/2612.Minimum Reverse Operations/README.md b/solution/2600-2699/2612.Minimum Reverse Operations/README.md index 90ccdf565879a..cfb538715242a 100644 --- a/solution/2600-2699/2612.Minimum Reverse Operations/README.md +++ b/solution/2600-2699/2612.Minimum Reverse Operations/README.md @@ -916,7 +916,7 @@ class TreeMultiSet { } ``` -````ts +```ts function minReverseOperations(n: number, p: number, banned: number[], k: number): number[] { const ans = new Array(n).fill(-1); const ts = new Array(2).fill(0).map(() => new TreapMultiSet()); @@ -1049,37 +1049,6 @@ class TreapMultiSet implements ITreapMultiSet { private readonly leftBound: T; private readonly rightBound: T; - /** - * - * @param compareFn A compare function which returns boolean or number - * @param leftBound defalut value is `-Infinity` - * @param rightBound defalut value is `Infinity` - * @description - * create a `MultiSet`, compare elements using `compareFn`, which is increasing order by default. - * @example - * ```ts - * interface Person { - name: string - age: number - } - - const leftBound = { - name: 'Alice', - age: -Infinity, - } - - const rightBound = { - name: 'Bob', - age: Infinity, - } - - const sortedList = new TreapMultiSet( - (a: Person, b: Person) => a.age - b.age, - leftBound, - rightBound - ) - * ``` - */ constructor(compareFn?: CompareFunction); constructor(compareFn: CompareFunction, leftBound: T, rightBound: T); constructor( @@ -1596,7 +1565,7 @@ class TreapMultiSet implements ITreapMultiSet { yield* this.reverseInOrder(root.left); } } -```` +``` ### **...** diff --git a/solution/2600-2699/2612.Minimum Reverse Operations/README_EN.md b/solution/2600-2699/2612.Minimum Reverse Operations/README_EN.md index 351acd7f18dc2..22b600b3b3f2c 100644 --- a/solution/2600-2699/2612.Minimum Reverse Operations/README_EN.md +++ b/solution/2600-2699/2612.Minimum Reverse Operations/README_EN.md @@ -902,7 +902,7 @@ class TreeMultiSet { } ``` -````ts +```ts function minReverseOperations(n: number, p: number, banned: number[], k: number): number[] { const ans = new Array(n).fill(-1); const ts = new Array(2).fill(0).map(() => new TreapMultiSet()); @@ -1035,37 +1035,6 @@ class TreapMultiSet implements ITreapMultiSet { private readonly leftBound: T; private readonly rightBound: T; - /** - * - * @param compareFn A compare function which returns boolean or number - * @param leftBound defalut value is `-Infinity` - * @param rightBound defalut value is `Infinity` - * @description - * create a `MultiSet`, compare elements using `compareFn`, which is increasing order by default. - * @example - * ```ts - * interface Person { - name: string - age: number - } - - const leftBound = { - name: 'Alice', - age: -Infinity, - } - - const rightBound = { - name: 'Bob', - age: Infinity, - } - - const sortedList = new TreapMultiSet( - (a: Person, b: Person) => a.age - b.age, - leftBound, - rightBound - ) - * ``` - */ constructor(compareFn?: CompareFunction); constructor(compareFn: CompareFunction, leftBound: T, rightBound: T); constructor( @@ -1582,7 +1551,7 @@ class TreapMultiSet implements ITreapMultiSet { yield* this.reverseInOrder(root.left); } } -```` +``` ### **...** diff --git a/solution/2700-2799/2746.Decremental String Concatenation/README_EN.md b/solution/2700-2799/2746.Decremental String Concatenation/README_EN.md index 3d0bb4d65827f..adbe1918047cd 100644 --- a/solution/2700-2799/2746.Decremental String Concatenation/README_EN.md +++ b/solution/2700-2799/2746.Decremental String Concatenation/README_EN.md @@ -68,15 +68,20 @@ It can be shown that the minimum possible length of str2 is 6. ## Solutions -**Solution 1: Case Discussion** +**Solution 1: Memoization Search** -We observe that the string 'AA' can only be followed by 'BB', and the string 'AB' can be placed at the beginning or end of the string. Therefore: +We notice that when concatenating strings, the first and last characters of the string will affect the length of the concatenated string. Therefore, we design a function $dfs(i, a, b)$, which represents the minimum length of the concatenated string starting from the $i$-th string, and the first character of the previously concatenated string is $a$, and the last character is $b$. -- If $x < y$, we can first alternately place 'BBAABBAA..BB', placing a total of $x$ 'AA' and $x+1$ 'BB', then place the remaining $z$ 'AB', with a total length of $(x \times 2 + z + 1) \times 2$; -- If $x > y$, we can first alternately place 'AABBAABB..AA', placing a total of $y$ 'BB' and $y+1$ 'AA', then place the remaining $z$ 'AB', with a total length of $(y \times 2 + z + 1) \times 2$; -- If $x = y$, we only need to alternately place 'AABB', placing a total of $x$ 'AA' and $y$ 'BB', then place the remaining $z$ 'AB', with a total length of $(x + y + z) \times 2$. +The execution process of the function $dfs(i, a, b)$ is as follows: -The time complexity is $O(1)$, and the space complexity is $O(1)$. +- If $i = n$, it means that all strings have been concatenated, return $0$; +- Otherwise, we consider concatenating the $i$-th string to the end or the beginning of the already concatenated string, and get the lengths $x$ and $y$ of the concatenated string, then $dfs(i, a, b) = \min(x, y) + |words[i]|$. + +To avoid repeated calculations, we use the method of memoization search. Specifically, we use a three-dimensional array $f$ to store all the return values of $dfs(i, a, b)$. When we need to calculate $dfs(i, a, b)$, if $f[i][a][b]$ has been calculated, we directly return $f[i][a][b]$; otherwise, we calculate the value of $dfs(i, a, b)$ according to the above recurrence relation, and store it in $f[i][a][b]$. + +In the main function, we directly return $|words[0]| + dfs(1, words[0][0], words[0][|words[0]| - 1])$. + +The time complexity is $O(n \times C^2)$, and the space complexity is $O(n \times C^2)$. Where $C$ represents the maximum length of the string. diff --git a/solution/3000-3099/3004.Maximum Subtree of the Same Color/README.md b/solution/3000-3099/3004.Maximum Subtree of the Same Color/README.md index bae54cf1d4945..6f122900f1a73 100644 --- a/solution/3000-3099/3004.Maximum Subtree of the Same Color/README.md +++ b/solution/3000-3099/3004.Maximum Subtree of the Same Color/README.md @@ -15,7 +15,7 @@

Return the size of such subtree with the maximum number of nodes possible.

 

-

+

Example 1:

@@ -33,7 +33,7 @@ Explanation: The whole tree has the same color, and the subtree rooted at node 0 has the most number of nodes which is 4. Hence, we return 4. -

+

Example 3:

diff --git a/solution/3000-3099/3004.Maximum Subtree of the Same Color/README_EN.md b/solution/3000-3099/3004.Maximum Subtree of the Same Color/README_EN.md index 12025da2b1868..f40af99b1621d 100644 --- a/solution/3000-3099/3004.Maximum Subtree of the Same Color/README_EN.md +++ b/solution/3000-3099/3004.Maximum Subtree of the Same Color/README_EN.md @@ -13,7 +13,7 @@

Return the size of such subtree with the maximum number of nodes possible.

 

-

+

Example 1:

@@ -31,7 +31,7 @@ Explanation: The whole tree has the same color, and the subtree rooted at node 0 has the most number of nodes which is 4. Hence, we return 4. -

+

Example 3:

diff --git a/solution/3000-3099/3004.Maximum Subtree of the Same Color/images/20231216-134017.png b/solution/3000-3099/3004.Maximum Subtree of the Same Color/images/20231216-134017.png new file mode 100644 index 0000000000000..baba124725ad5 Binary files /dev/null and b/solution/3000-3099/3004.Maximum Subtree of the Same Color/images/20231216-134017.png differ diff --git a/solution/3000-3099/3004.Maximum Subtree of the Same Color/images/20231216-134026.png b/solution/3000-3099/3004.Maximum Subtree of the Same Color/images/20231216-134026.png new file mode 100644 index 0000000000000..82f561649b7b3 Binary files /dev/null and b/solution/3000-3099/3004.Maximum Subtree of the Same Color/images/20231216-134026.png differ diff --git a/solution/DATABASE_README.md b/solution/DATABASE_README.md index 57fca238cf34f..5186eb64f7333 100644 --- a/solution/DATABASE_README.md +++ b/solution/DATABASE_README.md @@ -256,8 +256,8 @@ | 2989 | [班级表现](/solution/2900-2999/2989.Class%20Performance/README.md) | `数据库` | 中等 | 🔒 | | 2990 | [贷款类型](/solution/2900-2999/2990.Loan%20Types/README.md) | `数据库` | 简单 | 🔒 | | 2991 | [最好的三家酒庄](/solution/2900-2999/2991.Top%20Three%20Wineries/README.md) | `数据库` | 困难 | 🔒 | -| 2993 | [Friday Purchases I](/solution/2900-2999/2993.Friday%20Purchases%20I/README.md) | `数据库` | 中等 | 🔒 | -| 2994 | [Friday Purchases II](/solution/2900-2999/2994.Friday%20Purchases%20II/README.md) | `数据库` | 困难 | 🔒 | +| 2993 | [发生在周五的交易 I](/solution/2900-2999/2993.Friday%20Purchases%20I/README.md) | `数据库` | 中等 | 🔒 | +| 2994 | [发生在周五的交易 II](/solution/2900-2999/2994.Friday%20Purchases%20II/README.md) | `数据库` | 困难 | 🔒 | | 2995 | [观众变主播](/solution/2900-2999/2995.Viewers%20Turned%20Streamers/README.md) | `数据库` | 困难 | 🔒 | ## 版权 diff --git a/solution/README.md b/solution/README.md index b13f7312fe41a..88355e83468e7 100644 --- a/solution/README.md +++ b/solution/README.md @@ -3003,8 +3003,8 @@ | 2990 | [贷款类型](/solution/2900-2999/2990.Loan%20Types/README.md) | `数据库` | 简单 | 🔒 | | 2991 | [最好的三家酒庄](/solution/2900-2999/2991.Top%20Three%20Wineries/README.md) | `数据库` | 困难 | 🔒 | | 2992 | [自整除排列的数量](/solution/2900-2999/2992.Number%20of%20Self-Divisible%20Permutations/README.md) | `位运算`,`递归`,`数组`,`动态规划`,`状态压缩` | 中等 | 🔒 | -| 2993 | [Friday Purchases I](/solution/2900-2999/2993.Friday%20Purchases%20I/README.md) | `数据库` | 中等 | 🔒 | -| 2994 | [Friday Purchases II](/solution/2900-2999/2994.Friday%20Purchases%20II/README.md) | `数据库` | 困难 | 🔒 | +| 2993 | [发生在周五的交易 I](/solution/2900-2999/2993.Friday%20Purchases%20I/README.md) | `数据库` | 中等 | 🔒 | +| 2994 | [发生在周五的交易 II](/solution/2900-2999/2994.Friday%20Purchases%20II/README.md) | `数据库` | 困难 | 🔒 | | 2995 | [观众变主播](/solution/2900-2999/2995.Viewers%20Turned%20Streamers/README.md) | `数据库` | 困难 | 🔒 | | 2996 | [大于等于顺序前缀和的最小缺失整数](/solution/2900-2999/2996.Smallest%20Missing%20Integer%20Greater%20Than%20Sequential%20Prefix%20Sum/README.md) | `数组`,`哈希表`,`排序` | 简单 | 第 121 场双周赛 | | 2997 | [使数组异或和等于 K 的最少操作次数](/solution/2900-2999/2997.Minimum%20Number%20of%20Operations%20to%20Make%20Array%20XOR%20Equal%20to%20K/README.md) | `位运算`,`数组` | 中等 | 第 121 场双周赛 | @@ -3014,7 +3014,7 @@ | 3001 | [捕获黑皇后需要的最少移动次数](/solution/3000-3099/3001.Minimum%20Moves%20to%20Capture%20The%20Queen/README.md) | `数组`,`枚举` | 中等 | 第 379 场周赛 | | 3002 | [移除后集合的最多元素数](/solution/3000-3099/3002.Maximum%20Size%20of%20a%20Set%20After%20Removals/README.md) | `贪心`,`数组`,`哈希表` | 中等 | 第 379 场周赛 | | 3003 | [执行操作后的最大分割数量](/solution/3000-3099/3003.Maximize%20the%20Number%20of%20Partitions%20After%20Operations/README.md) | `位运算`,`字符串`,`动态规划`,`状态压缩` | 困难 | 第 379 场周赛 | -| 3004 | [Maximum Subtree of the Same Color](/solution/3000-3099/3004.Maximum%20Subtree%20of%20the%20Same%20Color/README.md) | | 中等 | 🔒 | +| 3004 | [相同颜色的最大子树](/solution/3000-3099/3004.Maximum%20Subtree%20of%20the%20Same%20Color/README.md) | | 中等 | 🔒 | ## 版权 diff --git a/solution/database-summary.md b/solution/database-summary.md index 8d8dd06e7a082..cea62ce31b3f2 100644 --- a/solution/database-summary.md +++ b/solution/database-summary.md @@ -246,6 +246,6 @@ - [2989.班级表现](/database-solution/2900-2999/2989.Class%20Performance/README.md) - [2990.贷款类型](/database-solution/2900-2999/2990.Loan%20Types/README.md) - [2991.最好的三家酒庄](/database-solution/2900-2999/2991.Top%20Three%20Wineries/README.md) - - [2993.Friday Purchases I](/database-solution/2900-2999/2993.Friday%20Purchases%20I/README.md) - - [2994.Friday Purchases II](/database-solution/2900-2999/2994.Friday%20Purchases%20II/README.md) + - [2993.发生在周五的交易 I](/database-solution/2900-2999/2993.Friday%20Purchases%20I/README.md) + - [2994.发生在周五的交易 II](/database-solution/2900-2999/2994.Friday%20Purchases%20II/README.md) - [2995.观众变主播](/database-solution/2900-2999/2995.Viewers%20Turned%20Streamers/README.md) diff --git a/solution/summary.md b/solution/summary.md index 80d1c8220c7fc..edbeebb7c74d9 100644 --- a/solution/summary.md +++ b/solution/summary.md @@ -3050,8 +3050,8 @@ - [2990.贷款类型](/solution/2900-2999/2990.Loan%20Types/README.md) - [2991.最好的三家酒庄](/solution/2900-2999/2991.Top%20Three%20Wineries/README.md) - [2992.自整除排列的数量](/solution/2900-2999/2992.Number%20of%20Self-Divisible%20Permutations/README.md) - - [2993.Friday Purchases I](/solution/2900-2999/2993.Friday%20Purchases%20I/README.md) - - [2994.Friday Purchases II](/solution/2900-2999/2994.Friday%20Purchases%20II/README.md) + - [2993.发生在周五的交易 I](/solution/2900-2999/2993.Friday%20Purchases%20I/README.md) + - [2994.发生在周五的交易 II](/solution/2900-2999/2994.Friday%20Purchases%20II/README.md) - [2995.观众变主播](/solution/2900-2999/2995.Viewers%20Turned%20Streamers/README.md) - [2996.大于等于顺序前缀和的最小缺失整数](/solution/2900-2999/2996.Smallest%20Missing%20Integer%20Greater%20Than%20Sequential%20Prefix%20Sum/README.md) - [2997.使数组异或和等于 K 的最少操作次数](/solution/2900-2999/2997.Minimum%20Number%20of%20Operations%20to%20Make%20Array%20XOR%20Equal%20to%20K/README.md) @@ -3063,4 +3063,4 @@ - [3001.捕获黑皇后需要的最少移动次数](/solution/3000-3099/3001.Minimum%20Moves%20to%20Capture%20The%20Queen/README.md) - [3002.移除后集合的最多元素数](/solution/3000-3099/3002.Maximum%20Size%20of%20a%20Set%20After%20Removals/README.md) - [3003.执行操作后的最大分割数量](/solution/3000-3099/3003.Maximize%20the%20Number%20of%20Partitions%20After%20Operations/README.md) - - [3004.Maximum Subtree of the Same Color](/solution/3000-3099/3004.Maximum%20Subtree%20of%20the%20Same%20Color/README.md) + - [3004.相同颜色的最大子树](/solution/3000-3099/3004.Maximum%20Subtree%20of%20the%20Same%20Color/README.md)