From 241a63662795c196e4d4341710489eade1741956 Mon Sep 17 00:00:00 2001 From: yanglbme Date: Fri, 8 Nov 2024 13:28:46 +0800 Subject: [PATCH] feat: add solutions to lc problem: No.3344 No.3344.Maximum Sized Array --- .../README.md" | 10 +- .../0410.Split Array Largest Sum/README.md | 6 +- .../README.md | 8 +- .../README_EN.md | 2 +- .../README_EN.md | 6 +- .../README.md | 2 +- .../README_EN.md | 8 +- .../README_EN.md | 6 +- .../README_EN.md | 2 +- .../README.md | 2 +- .../README.md | 2 +- .../3344.Maximum Sized Array/README.md | 255 ++++++++++++++++++ .../3344.Maximum Sized Array/README_EN.md | 253 +++++++++++++++++ .../3344.Maximum Sized Array/Solution.cpp | 28 ++ .../3344.Maximum Sized Array/Solution.go | 26 ++ .../3344.Maximum Sized Array/Solution.java | 24 ++ .../3344.Maximum Sized Array/Solution.py | 18 ++ .../3344.Maximum Sized Array/Solution.ts | 27 ++ solution/README.md | 1 + solution/README_EN.md | 1 + 20 files changed, 661 insertions(+), 26 deletions(-) create mode 100644 solution/3300-3399/3344.Maximum Sized Array/README.md create mode 100644 solution/3300-3399/3344.Maximum Sized Array/README_EN.md create mode 100644 solution/3300-3399/3344.Maximum Sized Array/Solution.cpp create mode 100644 solution/3300-3399/3344.Maximum Sized Array/Solution.go create mode 100644 solution/3300-3399/3344.Maximum Sized Array/Solution.java create mode 100644 solution/3300-3399/3344.Maximum Sized Array/Solution.py create mode 100644 solution/3300-3399/3344.Maximum Sized Array/Solution.ts diff --git "a/lcp/LCP 03. \346\234\272\345\231\250\344\272\272\345\244\247\345\206\222\351\231\251/README.md" "b/lcp/LCP 03. \346\234\272\345\231\250\344\272\272\345\244\247\345\206\222\351\231\251/README.md" index da59c19bea817..4a10c79e9ade4 100644 --- "a/lcp/LCP 03. \346\234\272\345\231\250\344\272\272\345\244\247\345\206\222\351\231\251/README.md" +++ "b/lcp/LCP 03. \346\234\272\345\231\250\344\272\272\345\244\247\345\206\222\351\231\251/README.md" @@ -247,7 +247,7 @@ class Solution { var visited: Set<[Int]> = [] var i = 0, j = 0 visited.insert([i, j]) - + for c in command { if c == "U" { j += 1 @@ -256,16 +256,16 @@ class Solution { } visited.insert([i, j]) } - + func canReach(_ targetX: Int, _ targetY: Int) -> Bool { let k = min(targetX / i, targetY / j) return visited.contains([targetX - k * i, targetY - k * j]) } - + if !canReach(x, y) { return false } - + for obstacle in obstacles { let obstacleX = obstacle[0] let obstacleY = obstacle[1] @@ -276,7 +276,7 @@ class Solution { return false } } - + return true } } diff --git a/solution/0400-0499/0410.Split Array Largest Sum/README.md b/solution/0400-0499/0410.Split Array Largest Sum/README.md index ddfe53ae1df6d..addd3804153c2 100644 --- a/solution/0400-0499/0410.Split Array Largest Sum/README.md +++ b/solution/0400-0499/0410.Split Array Largest Sum/README.md @@ -20,9 +20,11 @@ tags: -

给定一个非负整数数组 nums 和一个整数 k ,你需要将这个数组分成 k 个非空的连续子数组。

+

给定一个非负整数数组 nums 和一个整数 k ,你需要将这个数组分成 k 个非空的连续子数组,使得这 k 个子数组各自和的最大值 最小

-

设计一个算法使得这 k 个子数组各自和的最大值最小。

+

返回分割后最小的和的最大值。

+ +

子数组 是数组中连续的部份。

 

diff --git a/solution/0600-0699/0636.Exclusive Time of Functions/README.md b/solution/0600-0699/0636.Exclusive Time of Functions/README.md index cf2ae27ccdb7f..9dc839b951335 100644 --- a/solution/0600-0699/0636.Exclusive Time of Functions/README.md +++ b/solution/0600-0699/0636.Exclusive Time of Functions/README.md @@ -34,10 +34,10 @@ tags: 输入:n = 2, logs = ["0:start:0","1:start:2","1:end:5","0:end:6"] 输出:[3,4] 解释: -函数 0 在时间戳 0 的起始开始执行,执行 2 个单位时间,于时间戳 1 的末尾结束执行。 -函数 1 在时间戳 2 的起始开始执行,执行 4 个单位时间,于时间戳 5 的末尾结束执行。 -函数 0 在时间戳 6 的开始恢复执行,执行 1 个单位时间。 -所以函数 0 总共执行 2 + 1 = 3 个单位时间,函数 1 总共执行 4 个单位时间。 +函数 0 在时间戳 0 的起始开始执行,执行 2 个单位时间,于时间戳 1 的末尾结束执行。 +函数 1 在时间戳 2 的起始开始执行,执行 4 个单位时间,于时间戳 5 的末尾结束执行。 +函数 0 在时间戳 6 的开始恢复执行,执行 1 个单位时间。 +所以函数 0 总共执行 2 + 1 = 3 个单位时间,函数 1 总共执行 4 个单位时间。

示例 2:

diff --git a/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/README_EN.md b/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/README_EN.md index cb2236a60519a..ed387dd7185c1 100644 --- a/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/README_EN.md +++ b/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/README_EN.md @@ -35,7 +35,7 @@ tags:
 Input: root = [4,8,5,0,1,null,6]
 Output: 5
-Explanation:
+Explanation: 
 For the node with value 4: The average of its subtree is (4 + 8 + 5 + 0 + 1 + 6) / 6 = 24 / 6 = 4.
 For the node with value 5: The average of its subtree is (5 + 6) / 2 = 11 / 2 = 5.
 For the node with value 0: The average of its subtree is 0 / 1 = 0.
diff --git a/solution/2200-2299/2270.Number of Ways to Split Array/README_EN.md b/solution/2200-2299/2270.Number of Ways to Split Array/README_EN.md
index 0ce7fb9cea2d5..34c6224b03e69 100644
--- a/solution/2200-2299/2270.Number of Ways to Split Array/README_EN.md	
+++ b/solution/2200-2299/2270.Number of Ways to Split Array/README_EN.md	
@@ -36,7 +36,7 @@ tags:
 
 Input: nums = [10,4,-8,7]
 Output: 2
-Explanation:
+Explanation: 
 There are three ways of splitting nums into two non-empty parts:
 - Split nums at index 0. Then, the first part is [10], and its sum is 10. The second part is [4,-8,7], and its sum is 3. Since 10 >= 3, i = 0 is a valid split.
 - Split nums at index 1. Then, the first part is [10,4], and its sum is 14. The second part is [-8,7], and its sum is -1. Since 14 >= -1, i = 1 is a valid split.
@@ -49,9 +49,9 @@ Thus, the number of valid splits in nums is 2.
 
 Input: nums = [2,3,1,0]
 Output: 2
-Explanation:
+Explanation: 
 There are two valid splits in nums:
-- Split nums at index 1. Then, the first part is [2,3], and its sum is 5. The second part is [1,0], and its sum is 1. Since 5 >= 1, i = 1 is a valid split.
+- Split nums at index 1. Then, the first part is [2,3], and its sum is 5. The second part is [1,0], and its sum is 1. Since 5 >= 1, i = 1 is a valid split. 
 - Split nums at index 2. Then, the first part is [2,3,1], and its sum is 6. The second part is [0], and its sum is 0. Since 6 >= 0, i = 2 is a valid split.
 
diff --git a/solution/2500-2599/2526.Find Consecutive Integers from a Data Stream/README.md b/solution/2500-2599/2526.Find Consecutive Integers from a Data Stream/README.md index 75ccdec366088..86af0b96f6da1 100644 --- a/solution/2500-2599/2526.Find Consecutive Integers from a Data Stream/README.md +++ b/solution/2500-2599/2526.Find Consecutive Integers from a Data Stream/README.md @@ -43,7 +43,7 @@ tags: [null, false, false, true, false] 解释: -DataStream dataStream = new DataStream(4, 3); // value = 4, k = 3 +DataStream dataStream = new DataStream(4, 3); // value = 4, k = 3 dataStream.consec(4); // 数据流中只有 1 个整数,所以返回 False 。 dataStream.consec(4); // 数据流中只有 2 个整数 // 由于 2 小于 k ,返回 False 。 diff --git a/solution/2500-2599/2526.Find Consecutive Integers from a Data Stream/README_EN.md b/solution/2500-2599/2526.Find Consecutive Integers from a Data Stream/README_EN.md index 4810f74a3c607..e0d5e0651a7b2 100644 --- a/solution/2500-2599/2526.Find Consecutive Integers from a Data Stream/README_EN.md +++ b/solution/2500-2599/2526.Find Consecutive Integers from a Data Stream/README_EN.md @@ -42,11 +42,11 @@ tags: [null, false, false, true, false] Explanation -DataStream dataStream = new DataStream(4, 3); //value = 4, k = 3 -dataStream.consec(4); // Only 1 integer is parsed, so returns False. +DataStream dataStream = new DataStream(4, 3); //value = 4, k = 3 +dataStream.consec(4); // Only 1 integer is parsed, so returns False. dataStream.consec(4); // Only 2 integers are parsed. - // Since 2 is less than k, returns False. -dataStream.consec(4); // The 3 integers parsed are all equal to value, so returns True. + // Since 2 is less than k, returns False. +dataStream.consec(4); // The 3 integers parsed are all equal to value, so returns True. dataStream.consec(3); // The last k integers parsed in the stream are [4,4,3]. // Since 3 is not equal to value, it returns False.
diff --git a/solution/2500-2599/2528.Maximize the Minimum Powered City/README_EN.md b/solution/2500-2599/2528.Maximize the Minimum Powered City/README_EN.md index 88b70cc92173b..5092ff56c0de0 100644 --- a/solution/2500-2599/2528.Maximize the Minimum Powered City/README_EN.md +++ b/solution/2500-2599/2528.Maximize the Minimum Powered City/README_EN.md @@ -45,8 +45,8 @@ tags:
 Input: stations = [1,2,4,5,0], r = 1, k = 2
 Output: 5
-Explanation:
-One of the optimal ways is to install both the power stations at city 1.
+Explanation: 
+One of the optimal ways is to install both the power stations at city 1. 
 So stations will become [1,4,4,5,0].
 - City 0 is provided by 1 + 4 = 5 power stations.
 - City 1 is provided by 1 + 4 + 4 = 9 power stations.
@@ -62,7 +62,7 @@ Since it is not possible to obtain a larger power, we return 5.
 
 Input: stations = [4,4,4,4], r = 0, k = 3
 Output: 4
-Explanation:
+Explanation: 
 It can be proved that we cannot make the minimum power of a city greater than 4.
 
diff --git a/solution/2500-2599/2530.Maximal Score After Applying K Operations/README_EN.md b/solution/2500-2599/2530.Maximal Score After Applying K Operations/README_EN.md index a1dcfe3aa869e..8e6240a02b140 100644 --- a/solution/2500-2599/2530.Maximal Score After Applying K Operations/README_EN.md +++ b/solution/2500-2599/2530.Maximal Score After Applying K Operations/README_EN.md @@ -51,7 +51,7 @@ tags: Explanation: You can do the following operations: Operation 1: Select i = 1, so nums becomes [1,4,3,3,3]. Your score increases by 10. Operation 2: Select i = 1, so nums becomes [1,2,3,3,3]. Your score increases by 4. -Operation 3: Select i = 2, so nums becomes [1,1,1,3,3]. Your score increases by 3. +Operation 3: Select i = 2, so nums becomes [1,2,1,3,3]. Your score increases by 3. The final score is 10 + 4 + 3 = 17.
diff --git a/solution/3200-3299/3222.Find the Winning Player in Coin Game/README.md b/solution/3200-3299/3222.Find the Winning Player in Coin Game/README.md index d2d5efced4dcf..e5804e09db059 100644 --- a/solution/3200-3299/3222.Find the Winning Player in Coin Game/README.md +++ b/solution/3200-3299/3222.Find the Winning Player in Coin Game/README.md @@ -22,7 +22,7 @@ tags:

给你两个  整数 x 和 y ,分别表示价值为 75 和 10 的硬币的数目。

-

Alice 和 Bob 正在玩一个游戏。每一轮中,Alice 先进行操作,Bob 后操作。每次操作中,玩家需要拿出价值 总和 为 115 的硬币。如果一名玩家无法执行此操作,那么这名玩家 输掉 游戏。

+

Alice 和 Bob 正在玩一个游戏。每一轮中,Alice 先进行操作,Bob 后操作。每次操作中,玩家需要拿走价值 总和 为 115 的硬币。如果一名玩家无法执行此操作,那么这名玩家 输掉 游戏。

两名玩家都采取 最优 策略,请你返回游戏的赢家。

diff --git a/solution/3300-3399/3336.Find the Number of Subsequences With Equal GCD/README.md b/solution/3300-3399/3336.Find the Number of Subsequences With Equal GCD/README.md index cd23fec634515..c5f9b8468c147 100644 --- a/solution/3300-3399/3336.Find the Number of Subsequences With Equal GCD/README.md +++ b/solution/3300-3399/3336.Find the Number of Subsequences With Equal GCD/README.md @@ -21,7 +21,7 @@ tags:

给你一个整数数组 nums

-

请你统计所有满足一下条件的 非空 子序列(seq1, seq2) 的数量:

+

请你统计所有满足以下条件的 非空 子序列(seq1, seq2) 的数量: