diff --git a/solution/2200-2299/2243.Calculate Digit Sum of a String/README.md b/solution/2200-2299/2243.Calculate Digit Sum of a String/README.md index 96104c8905d1e..b01ced1d5bfd1 100644 --- a/solution/2200-2299/2243.Calculate Digit Sum of a String/README.md +++ b/solution/2200-2299/2243.Calculate Digit Sum of a String/README.md @@ -39,11 +39,11 @@ tags: 输出:"135" 解释: - 第一轮,将 s 分成:"111"、"112"、"222" 和 "23" 。 - 接着,计算每一组的数字和:1 + 1 + 1 = 3、1 + 1 + 2 = 4、2 + 2 + 2 = 6 和 2 + 3 = 5 。 + 接着,计算每一组的数字和:1 + 1 + 1 = 3、1 + 1 + 2 = 4、2 + 2 + 2 = 6 和 2 + 3 = 5 。 这样,s 在第一轮之后变成 "3" + "4" + "6" + "5" = "3465" 。 - 第二轮,将 s 分成:"346" 和 "5" 。 接着,计算每一组的数字和:3 + 4 + 6 = 13 、5 = 5 。 - 这样,s 在第二轮之后变成 "13" + "5" = "135" 。 + 这样,s 在第二轮之后变成 "13" + "5" = "135" 。 现在,s.length <= k ,所以返回 "135" 作为答案。 @@ -53,7 +53,7 @@ tags: 输出:"000" 解释: 将 "000", "000", and "00". -接着,计算每一组的数字和:0 + 0 + 0 = 0 、0 + 0 + 0 = 0 和 0 + 0 = 0 。 +接着,计算每一组的数字和:0 + 0 + 0 = 0 、0 + 0 + 0 = 0 和 0 + 0 = 0 。 s 变为 "0" + "0" + "0" = "000" ,其长度等于 k ,所以返回 "000" 。 diff --git a/solution/2200-2299/2243.Calculate Digit Sum of a String/README_EN.md b/solution/2200-2299/2243.Calculate Digit Sum of a String/README_EN.md index c423adb00dead..073fbee5bba78 100644 --- a/solution/2200-2299/2243.Calculate Digit Sum of a String/README_EN.md +++ b/solution/2200-2299/2243.Calculate Digit Sum of a String/README_EN.md @@ -37,13 +37,13 @@ tags:
Input: s = "11111222223", k = 3 Output: "135" -Explanation: +Explanation: - For the first round, we divide s into groups of size 3: "111", "112", "222", and "23". - Then we calculate the digit sum of each group: 1 + 1 + 1 = 3, 1 + 1 + 2 = 4, 2 + 2 + 2 = 6, and 2 + 3 = 5. + Then we calculate the digit sum of each group: 1 + 1 + 1 = 3, 1 + 1 + 2 = 4, 2 + 2 + 2 = 6, and 2 + 3 = 5. So, s becomes "3" + "4" + "6" + "5" = "3465" after the first round. - For the second round, we divide s into "346" and "5". - Then we calculate the digit sum of each group: 3 + 4 + 6 = 13, 5 = 5. - So, s becomes "13" + "5" = "135" after second round. + Then we calculate the digit sum of each group: 3 + 4 + 6 = 13, 5 = 5. + So, s becomes "13" + "5" = "135" after second round. Now, s.length <= k, so we return "135" as the answer.@@ -52,9 +52,9 @@ Now, s.length <= k, so we return "135" as the answer.
Input: s = "00000000", k = 3 Output: "000" -Explanation: +Explanation: We divide s into "000", "000", and "00". -Then we calculate the digit sum of each group: 0 + 0 + 0 = 0, 0 + 0 + 0 = 0, and 0 + 0 = 0. +Then we calculate the digit sum of each group: 0 + 0 + 0 = 0, 0 + 0 + 0 = 0, and 0 + 0 = 0. s becomes "0" + "0" + "0" = "000", whose length is equal to k, so we return "000".diff --git a/solution/3400-3499/3477.Fruits Into Baskets II/README.md b/solution/3400-3499/3477.Fruits Into Baskets II/README.md index 59a9bc57f85f6..55c55fb8c0900 100644 --- a/solution/3400-3499/3477.Fruits Into Baskets II/README.md +++ b/solution/3400-3499/3477.Fruits Into Baskets II/README.md @@ -2,6 +2,11 @@ comments: true difficulty: 简单 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3477.Fruits%20Into%20Baskets%20II/README.md +tags: + - 线段树 + - 数组 + - 二分查找 + - 模拟 --- diff --git a/solution/3400-3499/3477.Fruits Into Baskets II/README_EN.md b/solution/3400-3499/3477.Fruits Into Baskets II/README_EN.md index d6569c02b2eb7..180591ff0ffbe 100644 --- a/solution/3400-3499/3477.Fruits Into Baskets II/README_EN.md +++ b/solution/3400-3499/3477.Fruits Into Baskets II/README_EN.md @@ -2,6 +2,11 @@ comments: true difficulty: Easy edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3477.Fruits%20Into%20Baskets%20II/README_EN.md +tags: + - Segment Tree + - Array + - Binary Search + - Simulation --- diff --git a/solution/3400-3499/3478.Choose K Elements With Maximum Sum/README.md b/solution/3400-3499/3478.Choose K Elements With Maximum Sum/README.md index 99fa32054bb64..19e7f19697c2e 100644 --- a/solution/3400-3499/3478.Choose K Elements With Maximum Sum/README.md +++ b/solution/3400-3499/3478.Choose K Elements With Maximum Sum/README.md @@ -2,6 +2,10 @@ comments: true difficulty: 中等 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3478.Choose%20K%20Elements%20With%20Maximum%20Sum/README.md +tags: + - 数组 + - 排序 + - 堆(优先队列) --- diff --git a/solution/3400-3499/3478.Choose K Elements With Maximum Sum/README_EN.md b/solution/3400-3499/3478.Choose K Elements With Maximum Sum/README_EN.md index 9832f8c87ecfe..9cb543eac3868 100644 --- a/solution/3400-3499/3478.Choose K Elements With Maximum Sum/README_EN.md +++ b/solution/3400-3499/3478.Choose K Elements With Maximum Sum/README_EN.md @@ -2,6 +2,10 @@ comments: true difficulty: Medium edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3478.Choose%20K%20Elements%20With%20Maximum%20Sum/README_EN.md +tags: + - Array + - Sorting + - Heap (Priority Queue) --- diff --git a/solution/3400-3499/3479.Fruits Into Baskets III/README.md b/solution/3400-3499/3479.Fruits Into Baskets III/README.md index 68d45fe44eda6..4f8c1fccc3f1d 100644 --- a/solution/3400-3499/3479.Fruits Into Baskets III/README.md +++ b/solution/3400-3499/3479.Fruits Into Baskets III/README.md @@ -2,6 +2,11 @@ comments: true difficulty: 中等 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3479.Fruits%20Into%20Baskets%20III/README.md +tags: + - 线段树 + - 数组 + - 二分查找 + - 有序集合 --- diff --git a/solution/3400-3499/3479.Fruits Into Baskets III/README_EN.md b/solution/3400-3499/3479.Fruits Into Baskets III/README_EN.md index 180ca62d7b124..69d7386b37cb3 100644 --- a/solution/3400-3499/3479.Fruits Into Baskets III/README_EN.md +++ b/solution/3400-3499/3479.Fruits Into Baskets III/README_EN.md @@ -2,6 +2,11 @@ comments: true difficulty: Medium edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3479.Fruits%20Into%20Baskets%20III/README_EN.md +tags: + - Segment Tree + - Array + - Binary Search + - Ordered Set --- @@ -15,7 +20,6 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3479.Fr
You are given two arrays of integers, fruits
and baskets
, each of length n
, where fruits[i]
represents the quantity of the ith
type of fruit, and baskets[j]
represents the capacity of the jth
basket.
From left to right, place the fruits according to these rules:
diff --git a/solution/3400-3499/3480.Maximize Subarrays After Removing One Conflicting Pair/README.md b/solution/3400-3499/3480.Maximize Subarrays After Removing One Conflicting Pair/README.md index 4313392f9c484..352da5080d42f 100644 --- a/solution/3400-3499/3480.Maximize Subarrays After Removing One Conflicting Pair/README.md +++ b/solution/3400-3499/3480.Maximize Subarrays After Removing One Conflicting Pair/README.md @@ -2,6 +2,11 @@ comments: true difficulty: 困难 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3480.Maximize%20Subarrays%20After%20Removing%20One%20Conflicting%20Pair/README.md +tags: + - 线段树 + - 数组 + - 枚举 + - 前缀和 --- diff --git a/solution/3400-3499/3480.Maximize Subarrays After Removing One Conflicting Pair/README_EN.md b/solution/3400-3499/3480.Maximize Subarrays After Removing One Conflicting Pair/README_EN.md index 693b42801e17b..622dce38fd5f6 100644 --- a/solution/3400-3499/3480.Maximize Subarrays After Removing One Conflicting Pair/README_EN.md +++ b/solution/3400-3499/3480.Maximize Subarrays After Removing One Conflicting Pair/README_EN.md @@ -2,6 +2,11 @@ comments: true difficulty: Hard edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3480.Maximize%20Subarrays%20After%20Removing%20One%20Conflicting%20Pair/README_EN.md +tags: + - Segment Tree + - Array + - Enumeration + - Prefix Sum --- @@ -15,12 +20,11 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3480.MaYou are given an integer n
which represents an array nums
containing the numbers from 1 to n
in order. Additionally, you are given a 2D array conflictingPairs
, where conflictingPairs[i] = [a, b]
indicates that a
and b
form a conflicting pair.
Remove exactly one element from conflictingPairs
. Afterward, count the number of non-empty subarrays of nums
which do not contain both a
and b
for any remaining conflicting pair [a, b]
.
Remove exactly one element from conflictingPairs
. Afterward, count the number of non-empty subarrays of nums
which do not contain both a
and b
for any remaining conflicting pair [a, b]
.
Return the maximum number of subarrays possible after removing exactly one conflicting pair.
-A subarray is a contiguous, non-empty sequence of elements within an array. +
Example 1:
diff --git a/solution/3400-3499/3481.Apply Substitutions/README.md b/solution/3400-3499/3481.Apply Substitutions/README.md new file mode 100644 index 0000000000000..a77ddd32a54fa --- /dev/null +++ b/solution/3400-3499/3481.Apply Substitutions/README.md @@ -0,0 +1,111 @@ +--- +comments: true +difficulty: 中等 +edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3481.Apply%20Substitutions/README.md +--- + + + +# [3481. Apply Substitutions 🔒](https://leetcode.cn/problems/apply-substitutions) + +[English Version](/solution/3400-3499/3481.Apply%20Substitutions/README_EN.md) + +## 题目描述 + + + +You are given a replacements
mapping and a text
string that may contain placeholders formatted as %var%
, where each var
corresponds to a key in the replacements
mapping. Each replacement value may itself contain one or more such placeholders. Each placeholder is replaced by the value associated with its corresponding replacement key.
Return the fully substituted text
string which does not contain any placeholders.
+
Example 1:
+ +Input: replacements = [["A","abc"],["B","def"]], text = "%A%_%B%"
+ +Output: "abc_def"
+ +Explanation:
+ +"A"
with "abc"
and "B"
with "def"
.%A%
with "abc"
and %B%
with "def"
in the text."abc_def"
.Example 2:
+ +Input: replacements = [["A","bce"],["B","ace"],["C","abc%B%"]], text = "%A%_%B%_%C%"
+ +Output: "bce_ace_abcace"
+ +Explanation:
+ +"A"
with "bce"
, "B"
with "ace"
, and "C"
with "abc%B%"
.%A%
with "bce"
and %B%
with "ace"
in the text.%C%
, substitute %B%
in "abc%B%"
with "ace"
to obtain "abcace"
."bce_ace_abcace"
.+
Constraints:
+ +1 <= replacements.length <= 10
replacements
is a two-element list [key, value]
, where:
+ key
is a single uppercase English letter.value
is a non-empty string of at most 8 characters that may contain zero or more placeholders formatted as %<key>%
.text
string is formed by concatenating all key placeholders (formatted as %<key>%
) randomly from the replacements mapping, separated by underscores.text.length == 4 * replacements.length - 1
text
or in any replacement value corresponds to a key in the replacements
mapping.You are given a replacements
mapping and a text
string that may contain placeholders formatted as %var%
, where each var
corresponds to a key in the replacements
mapping. Each replacement value may itself contain one or more such placeholders. Each placeholder is replaced by the value associated with its corresponding replacement key.
Return the fully substituted text
string which does not contain any placeholders.
+
Example 1:
+ +Input: replacements = [["A","abc"],["B","def"]], text = "%A%_%B%"
+ +Output: "abc_def"
+ +Explanation:
+ +"A"
with "abc"
and "B"
with "def"
.%A%
with "abc"
and %B%
with "def"
in the text."abc_def"
.Example 2:
+ +Input: replacements = [["A","bce"],["B","ace"],["C","abc%B%"]], text = "%A%_%B%_%C%"
+ +Output: "bce_ace_abcace"
+ +Explanation:
+ +"A"
with "bce"
, "B"
with "ace"
, and "C"
with "abc%B%"
.%A%
with "bce"
and %B%
with "ace"
in the text.%C%
, substitute %B%
in "abc%B%"
with "ace"
to obtain "abcace"
."bce_ace_abcace"
.+
Constraints:
+ +1 <= replacements.length <= 10
replacements
is a two-element list [key, value]
, where:
+ key
is a single uppercase English letter.value
is a non-empty string of at most 8 characters that may contain zero or more placeholders formatted as %<key>%
.text
string is formed by concatenating all key placeholders (formatted as %<key>%
) randomly from the replacements mapping, separated by underscores.text.length == 4 * replacements.length - 1
text
or in any replacement value corresponds to a key in the replacements
mapping.Table: Employees
++----------------+---------+ +| Column Name | Type | ++----------------+---------+ +| employee_id | int | +| employee_name | varchar | +| manager_id | int | +| salary | int | +| department | varchar | ++----------------+----------+ +employee_id is the unique key for this table. +Each row contains information about an employee, including their ID, name, their manager's ID, salary, and department. +manager_id is null for the top-level manager (CEO). ++ +
Write a solution to analyze the organizational hierarchy and answer the following:
+ +1
, employees reporting directly to the CEO are level 2
, and so on).Return the result table ordered by the result ordered by level in ascending order, then by budget in descending order, and finally by employee_name in ascending order.
+ +The result format is in the following example.
+ ++
Example:
+ +Input:
+ +Employees table:
+ +++-------------+---------------+------------+--------+-------------+ +| employee_id | employee_name | manager_id | salary | department | ++-------------+---------------+------------+--------+-------------+ +| 1 | Alice | null | 12000 | Executive | +| 2 | Bob | 1 | 10000 | Sales | +| 3 | Charlie | 1 | 10000 | Engineering | +| 4 | David | 2 | 7500 | Sales | +| 5 | Eva | 2 | 7500 | Sales | +| 6 | Frank | 3 | 9000 | Engineering | +| 7 | Grace | 3 | 8500 | Engineering | +| 8 | Hank | 4 | 6000 | Sales | +| 9 | Ivy | 6 | 7000 | Engineering | +| 10 | Judy | 6 | 7000 | Engineering | ++-------------+---------------+------------+--------+-------------+ ++ +
Output:
+ +++-------------+---------------+-------+-----------+--------+ +| employee_id | employee_name | level | team_size | budget | ++-------------+---------------+-------+-----------+--------+ +| 1 | Alice | 1 | 9 | 84500 | +| 3 | Charlie | 2 | 4 | 41500 | +| 2 | Bob | 2 | 3 | 31000 | +| 6 | Frank | 3 | 2 | 23000 | +| 4 | David | 3 | 1 | 13500 | +| 7 | Grace | 3 | 0 | 8500 | +| 5 | Eva | 3 | 0 | 7500 | +| 9 | Ivy | 4 | 0 | 7000 | +| 10 | Judy | 4 | 0 | 7000 | +| 8 | Hank | 4 | 0 | 6000 | ++-------------+---------------+-------+-----------+--------+ ++ +
Explanation:
+ +Note:
+ +Table: Employees
++----------------+---------+ +| Column Name | Type | ++----------------+---------+ +| employee_id | int | +| employee_name | varchar | +| manager_id | int | +| salary | int | +| department | varchar | ++----------------+----------+ +employee_id is the unique key for this table. +Each row contains information about an employee, including their ID, name, their manager's ID, salary, and department. +manager_id is null for the top-level manager (CEO). ++ +
Write a solution to analyze the organizational hierarchy and answer the following:
+ +1
, employees reporting directly to the CEO are level 2
, and so on).Return the result table ordered by the result ordered by level in ascending order, then by budget in descending order, and finally by employee_name in ascending order.
+ +The result format is in the following example.
+ ++
Example:
+ +Input:
+ +Employees table:
+ +++-------------+---------------+------------+--------+-------------+ +| employee_id | employee_name | manager_id | salary | department | ++-------------+---------------+------------+--------+-------------+ +| 1 | Alice | null | 12000 | Executive | +| 2 | Bob | 1 | 10000 | Sales | +| 3 | Charlie | 1 | 10000 | Engineering | +| 4 | David | 2 | 7500 | Sales | +| 5 | Eva | 2 | 7500 | Sales | +| 6 | Frank | 3 | 9000 | Engineering | +| 7 | Grace | 3 | 8500 | Engineering | +| 8 | Hank | 4 | 6000 | Sales | +| 9 | Ivy | 6 | 7000 | Engineering | +| 10 | Judy | 6 | 7000 | Engineering | ++-------------+---------------+------------+--------+-------------+ ++ +
Output:
+ +++-------------+---------------+-------+-----------+--------+ +| employee_id | employee_name | level | team_size | budget | ++-------------+---------------+-------+-----------+--------+ +| 1 | Alice | 1 | 9 | 84500 | +| 3 | Charlie | 2 | 4 | 41500 | +| 2 | Bob | 2 | 3 | 31000 | +| 6 | Frank | 3 | 2 | 23000 | +| 4 | David | 3 | 1 | 13500 | +| 7 | Grace | 3 | 0 | 8500 | +| 5 | Eva | 3 | 0 | 7500 | +| 9 | Ivy | 4 | 0 | 7000 | +| 10 | Judy | 4 | 0 | 7000 | +| 8 | Hank | 4 | 0 | 6000 | ++-------------+---------------+-------+-----------+--------+ ++ +
Explanation:
+ +Note:
+ +