diff --git a/solution/0000-0099/0020.Valid Parentheses/README.md b/solution/0000-0099/0020.Valid Parentheses/README.md index 4e6adcb27adec..e4c364fe798a6 100644 --- a/solution/0000-0099/0020.Valid Parentheses/README.md +++ b/solution/0000-0099/0020.Valid Parentheses/README.md @@ -29,26 +29,37 @@ tags:
-
示例 1:
+示例 1:
--输入:s = "()" -输出:true -+
输入:s = "()"
-示例 2:
+输出:true
+-输入:s = "()[]{}" -输出:true -+
示例 2:
-示例 3:
+输入:s = "()[]{}"
--输入:s = "(]" -输出:false -+
输出:true
+示例 3:
+ +输入:s = "(]"
+ +输出:false
+示例 4:
+ +输入:s = "([])"
+ +输出:true
+diff --git a/solution/0100-0199/0176.Second Highest Salary/README.md b/solution/0100-0199/0176.Second Highest Salary/README.md index 7e2f110891385..186c1cb8fa9d1 100644 --- a/solution/0100-0199/0176.Second Highest Salary/README.md +++ b/solution/0100-0199/0176.Second Highest Salary/README.md @@ -27,13 +27,13 @@ tags: | id | int | | salary | int | +-------------+------+ -在 SQL 中,id 是这个表的主键。 +id 是这个表的主键。 表的每一行包含员工的工资信息。
-
查询并返回 Employee
表中第二高的薪水 。如果不存在第二高的薪水,查询应该返回 null(Pandas 则返回 None)
。
查询并返回 Employee
表中第二高的 不同 薪水 。如果不存在第二高的薪水,查询应该返回 null(Pandas 则返回 None)
。
查询结果如下例所示。
diff --git a/solution/0100-0199/0176.Second Highest Salary/README_EN.md b/solution/0100-0199/0176.Second Highest Salary/README_EN.md index dc497121217dd..dc07f75586d2b 100644 --- a/solution/0100-0199/0176.Second Highest Salary/README_EN.md +++ b/solution/0100-0199/0176.Second Highest Salary/README_EN.md @@ -31,7 +31,7 @@ Each row of this table contains information about the salary of an employee.-
Write a solution to find the second highest salary from the Employee
table. If there is no second highest salary, return null (return None in Pandas)
.
Write a solution to find the second highest distinct salary from the Employee
table. If there is no second highest salary, return null (return None in Pandas)
.
The result format is in the following example.
diff --git a/solution/0100-0199/0197.Rising Temperature/README_EN.md b/solution/0100-0199/0197.Rising Temperature/README_EN.md index 5902232ce59ae..cfcc012acfc2d 100644 --- a/solution/0100-0199/0197.Rising Temperature/README_EN.md +++ b/solution/0100-0199/0197.Rising Temperature/README_EN.md @@ -33,7 +33,7 @@ This table contains information about the temperature on a certain day.-
Write a solution to find all dates' Id
with higher temperatures compared to its previous dates (yesterday).
Write a solution to find all dates' id
with higher temperatures compared to its previous dates (yesterday).
Return the result table in any order.
diff --git a/solution/0200-0299/0205.Isomorphic Strings/README_EN.md b/solution/0200-0299/0205.Isomorphic Strings/README_EN.md index 0b05304ac08f9..2f3eb16d4b8b7 100644 --- a/solution/0200-0299/0205.Isomorphic Strings/README_EN.md +++ b/solution/0200-0299/0205.Isomorphic Strings/README_EN.md @@ -25,15 +25,42 @@ tags:
Example 1:
-Input: s = "egg", t = "add" -Output: true -
Example 2:
-Input: s = "foo", t = "bar" -Output: false -
Example 3:
-Input: s = "paper", t = "title" -Output: true -+ +
Input: s = "egg", t = "add"
+ +Output: true
+ +Explanation:
+ +The strings s
and t
can be made identical by:
'e'
to 'a'
.'g'
to 'd'
.Example 2:
+ +Input: s = "foo", t = "bar"
+ +Output: false
+ +Explanation:
+ +The strings s
and t
can not be made identical as 'o'
needs to be mapped to both 'a'
and 'r'
.
Example 3:
+ +Input: s = "paper", t = "title"
+ +Output: true
+
Constraints:
diff --git a/solution/0200-0299/0242.Valid Anagram/README.md b/solution/0200-0299/0242.Valid Anagram/README.md index 45b5a4d81a9c8..ffd047fc8c537 100644 --- a/solution/0200-0299/0242.Valid Anagram/README.md +++ b/solution/0200-0299/0242.Valid Anagram/README.md @@ -20,11 +20,11 @@ tags:给定两个字符串 s
和 t
,编写一个函数来判断 t
是否是 s
的字母异位词。
注意:若 s
和 t
中每个字符出现的次数都相同,则称 s
和 t
互为字母异位词。
字母异位词 是通过重新排列不同单词或短语的字母而形成的单词或短语,通常只使用所有原始字母一次。
-+
-
示例 1:
+示例 1:
输入: s = "anagram", t = "nagaram" @@ -37,18 +37,18 @@ tags: 输入: s = "rat", t = "car" 输出: false-
+
提示:
1 <= s.length, t.length <= 5 * 104
s
和 t
仅包含小写字母1 <= s.length, t.length <= 5 * 104
s
和 t
仅包含小写字母+
-
进阶: 如果输入字符串包含 unicode 字符怎么办?你能否调整你的解法来应对这种情况?
+进阶: 如果输入字符串包含 unicode 字符怎么办?你能否调整你的解法来应对这种情况?
diff --git a/solution/0400-0499/0455.Assign Cookies/README.md b/solution/0400-0499/0455.Assign Cookies/README.md index b5b132e42c223..8d64455509043 100644 --- a/solution/0400-0499/0455.Assign Cookies/README.md +++ b/solution/0400-0499/0455.Assign Cookies/README.md @@ -21,7 +21,7 @@ tags:假设你是一位很棒的家长,想要给你的孩子们一些小饼干。但是,每个孩子最多只能给一块饼干。
-对每个孩子 i
,都有一个胃口值 g[i]
,这是能让孩子们满足胃口的饼干的最小尺寸;并且每块饼干 j
,都有一个尺寸 s[j]
。如果 s[j] >= g[i]
,我们可以将这个饼干 j
分配给孩子 i
,这个孩子会得到满足。你的目标是尽可能满足越多数量的孩子,并输出这个最大数值。
对每个孩子 i
,都有一个胃口值 g[i]
,这是能让孩子们满足胃口的饼干的最小尺寸;并且每块饼干 j
,都有一个尺寸 s[j]
。如果 s[j] >= g[i]
,我们可以将这个饼干 j
分配给孩子 i
,这个孩子会得到满足。你的目标是满足尽可能多的孩子,并输出这个最大数值。
示例 1:
diff --git a/solution/0500-0599/0592.Fraction Addition and Subtraction/README.md b/solution/0500-0599/0592.Fraction Addition and Subtraction/README.md index f3014f3f82008..d6f2bc1fcfebd 100644 --- a/solution/0500-0599/0592.Fraction Addition and Subtraction/README.md +++ b/solution/0500-0599/0592.Fraction Addition and Subtraction/README.md @@ -20,7 +20,7 @@ tags:给定一个表示分数加减运算的字符串 expression
,你需要返回一个字符串形式的计算结果。
这个结果应该是不可约分的分数,即最简分数。 如果最终结果是一个整数,例如 2
,你需要将它转换成分数形式,其分母为 1
。所以在上述例子中, 2
应该被转换为 2/1
。
这个结果应该是不可约分的分数,即 最简分数。 如果最终结果是一个整数,例如 2
,你需要将它转换成分数形式,其分母为 1
。所以在上述例子中, 2
应该被转换为 2/1
。
@@ -52,9 +52,9 @@ tags:
'0'
到 '9'
的数字,以及 '/'
, '+'
和 '-'
。 ±分子/分母
。如果输入的第一个分数或者输出的分数是正数,则 '+'
会被省略掉。[1,10]
。 如果分母是 1,意味着这个分数实际上是一个整数。id
是该表的主键(唯一值)列。
该表的每一行都表示学生的姓名和 ID。
-id 是一个连续的增量。
+ID 序列始终从 1 开始并连续增加。
diff --git a/solution/0600-0699/0673.Number of Longest Increasing Subsequence/README_EN.md b/solution/0600-0699/0673.Number of Longest Increasing Subsequence/README_EN.md index 4ed3e06931683..52b28ef54f311 100644 --- a/solution/0600-0699/0673.Number of Longest Increasing Subsequence/README_EN.md +++ b/solution/0600-0699/0673.Number of Longest Increasing Subsequence/README_EN.md @@ -46,6 +46,7 @@ tags:
1 <= nums.length <= 2000
-106 <= nums[i] <= 106
自除数 不允许包含 0 。
-给定两个整数 left
和 right
,返回一个列表,列表的元素是范围 [left, right]
内所有的 自除数 。
给定两个整数 left
和 right
,返回一个列表,列表的元素是范围 [left, right]
(包括两个端点)内所有的 自除数 。
diff --git a/solution/0700-0799/0728.Self Dividing Numbers/README_EN.md b/solution/0700-0799/0728.Self Dividing Numbers/README_EN.md index c26e0dc44b1af..99af263bf3e85 100644 --- a/solution/0700-0799/0728.Self Dividing Numbers/README_EN.md +++ b/solution/0700-0799/0728.Self Dividing Numbers/README_EN.md @@ -24,7 +24,7 @@ tags:
A self-dividing number is not allowed to contain the digit zero.
-Given two integers left
and right
, return a list of all the self-dividing numbers in the range [left, right]
.
Given two integers left
and right
, return a list of all the self-dividing numbers in the range [left, right]
(both inclusive).
Example 1:
diff --git a/solution/0800-0899/0840.Magic Squares In Grid/README.md b/solution/0800-0899/0840.Magic Squares In Grid/README.md index 2e9b56973f791..5ec1db887dc13 100644 --- a/solution/0800-0899/0840.Magic Squares In Grid/README.md +++ b/solution/0800-0899/0840.Magic Squares In Grid/README.md @@ -21,7 +21,7 @@ tags:3 x 3
的幻方是一个填充有 从 1
到 9
的不同数字的 3 x 3
矩阵,其中每行,每列以及两条对角线上的各数之和都相等。
给定一个由整数组成的row x col
的 grid
,其中有多少个 3 × 3
的 “幻方” 子矩阵?(每个子矩阵都是连续的)。
给定一个由整数组成的row x col
的 grid
,其中有多少个 3 × 3
的 “幻方” 子矩阵?
注意:虽然幻方只能包含 1 到 9 的数字,但 grid
可以包含最多15的数字。
给你一个大小为 n x n
的整数矩阵 board
,方格按从 1
到 n2
编号,编号遵循 转行交替方式 ,从左下角开始 (即,从 board[n - 1][0]
开始)每一行交替方向。
给你一个大小为 n x n
的整数矩阵 board
,方格按从 1
到 n2
编号,编号遵循 转行交替方式 ,从左下角开始 (即,从 board[n - 1][0]
开始)的每一行改变方向。
玩家从棋盘上的方格 1
(总是在最后一行、第一列)开始出发。
每一回合,玩家需要从当前方格 curr
开始出发,按下述要求前进:
你一开始位于棋盘上的方格 1
。每一回合,玩家需要从当前方格 curr
开始出发,按下述要求前进:
next
,目标方格的编号符合范围 [curr + 1, min(curr + 6, n2)]
。
+ next
,目标方格的编号在范围 [curr + 1, min(curr + 6, n2)]
。
r
行 c
列的棋盘,按前述方法编号,棋盘格中可能存在 “蛇” 或 “梯子”;如果 board[r][c] != -1
,那个蛇或梯子的目的地将会是 board[r][c]
。编号为 1
和 n2
的方格不是任何蛇或梯子的起点。
如果 board[r][c] != -1
,位于 r
行 c
列的棋盘格中可能存在 “蛇” 或 “梯子”。那个蛇或梯子的目的地将会是 board[r][c]
。编号为 1
和 n2
的方格不是任何蛇或梯子的起点。
注意,玩家在每回合的前进过程中最多只能爬过蛇或梯子一次:就算目的地是另一条蛇或梯子的起点,玩家也 不能 继续移动。
[[-1,4],[-1,3]]
,第一次移动,玩家的目标方格是 2
。那么这个玩家将会顺着梯子到达方格 3
,但 不能 顺着方格 3
上的梯子前往方格 4
。[[-1,4],[-1,3]]
,第一次移动,玩家的目标方格是 2
。那么这个玩家将会顺着梯子到达方格 3
,但 不能 顺着方格 3
上的梯子前往方格 4
。(简单来说,类似飞行棋,玩家掷出骰子点数后移动对应格数,遇到单向的路径(即梯子或蛇)可以直接跳到路径的终点,但如果多个路径首尾相连,也不能连续跳多个路径)返回达到编号为 n2
的方格所需的最少移动次数,如果不可能,则返回 -1
。
在一个长度 无限 的数轴上,第 i
颗石子的位置为 stones[i]
。如果一颗石子的位置最小/最大,那么该石子被称作 端点石子 。
在 X 轴上有一些不同位置的石子。给定一个整数数组 stones
表示石子的位置。
每个回合,你可以将一颗端点石子拿起并移动到一个未占用的位置,使得该石子不再是一颗端点石子。
+如果一个石子在最小或最大的位置,称其为 端点石子。每个回合,你可以将一颗 端点石子 拿起并移动到一个未占用的位置,使得该石子不再是一颗 端点石子。
-值得注意的是,如果石子像 stones = [1,2,5]
这样,你将 无法 移动位于位置 5 的端点石子,因为无论将它移动到任何位置(例如 0 或 3),该石子都仍然会是端点石子。
stones = [1,2,5]
这样,你将 无法 移动位于位置 5
的端点石子,因为无论将它移动到任何位置(例如 0
或 3
),该石子都仍然会是端点石子。当你无法进行任何移动时,即,这些石子的位置连续时,游戏结束。
-要使游戏结束,你可以执行的最小和最大移动次数分别是多少? 以长度为 2 的数组形式返回答案:answer = [minimum_moves, maximum_moves]
。
以长度为 2 的数组形式返回答案,其中:
+ +answer[0]
是你可以移动的最小次数answer[1]
是你可以移动的最大次数。+
示例 1:
@@ -39,38 +46,32 @@ tags: 输入:[7,4,9] 输出:[1,2] 解释: -我们可以移动一次,4 -> 8,游戏结束。 -或者,我们可以移动两次 9 -> 5,4 -> 6,游戏结束。 +我们可以移动一次,4 -> 8,游戏结束。 +或者,我们可以移动两次 9 -> 5,4 -> 6,游戏结束。 -示例 2:
+示例 2:
输入:[6,5,4,3,10] 输出:[2,3] 解释: -我们可以移动 3 -> 8,接着是 10 -> 7,游戏结束。 -或者,我们可以移动 3 -> 7, 4 -> 8, 5 -> 9,游戏结束。 -注意,我们无法进行 10 -> 2 这样的移动来结束游戏,因为这是不合要求的移动。 +我们可以移动 3 -> 8,接着是 10 -> 7,游戏结束。 +或者,我们可以移动 3 -> 7, 4 -> 8, 5 -> 9,游戏结束。 +注意,我们无法进行 10 -> 2 这样的移动来结束游戏,因为这是不合要求的移动。-
示例 3:
- --输入:[100,101,104,102,103] -输出:[0,0]- -
+
提示:
3 <= stones.length <= 10^4
1 <= stones[i] <= 10^9
stones[i]
的值各不相同。3 <= stones.length <= 104
1 <= stones[i] <= 109
stones
的值各不相同。+
diff --git a/solution/1000-1099/1052.Grumpy Bookstore Owner/README.md b/solution/1000-1099/1052.Grumpy Bookstore Owner/README.md index a2858cd1439ff..fb35423d8191a 100644 --- a/solution/1000-1099/1052.Grumpy Bookstore Owner/README.md +++ b/solution/1000-1099/1052.Grumpy Bookstore Owner/README.md @@ -21,7 +21,7 @@ tags:
有一个书店老板,他的书店开了 n
分钟。每分钟都有一些顾客进入这家商店。给定一个长度为 n
的整数数组 customers
,其中 customers[i]
是在第 i
分钟开始时进入商店的顾客数量,所有这些顾客在第 i
分钟结束后离开。
在某些时候,书店老板会生气。 如果书店老板在第 i
分钟生气,那么 grumpy[i] = 1
,否则 grumpy[i] = 0
。
在某些分钟内,书店老板会生气。 如果书店老板在第 i
分钟生气,那么 grumpy[i] = 1
,否则 grumpy[i] = 0
。
当书店老板生气时,那一分钟的顾客就会不满意,若老板不生气则顾客是满意的。
diff --git a/solution/1100-1199/1140.Stone Game II/README.md b/solution/1100-1199/1140.Stone Game II/README.md index 84d60a634f76b..a0fc0b8726004 100644 --- a/solution/1100-1199/1140.Stone Game II/README.md +++ b/solution/1100-1199/1140.Stone Game II/README.md @@ -22,15 +22,15 @@ tags: -爱丽丝和鲍勃继续他们的石子游戏。许多堆石子 排成一行,每堆都有正整数颗石子 piles[i]
。游戏以谁手中的石子最多来决出胜负。
Alice 和 Bob 继续他们的石子游戏。许多堆石子 排成一行,每堆都有正整数颗石子 piles[i]
。游戏以谁手中的石子最多来决出胜负。
爱丽丝和鲍勃轮流进行,爱丽丝先开始。最初,M = 1
。
Alice 和 Bob 轮流进行,Alice 先开始。最初,M = 1
。
在每个玩家的回合中,该玩家可以拿走剩下的 前 X
堆的所有石子,其中 1 <= X <= 2M
。然后,令 M = max(M, X)
。
游戏一直持续到所有石子都被拿走。
-假设爱丽丝和鲍勃都发挥出最佳水平,返回爱丽丝可以得到的最大数量的石头。
+假设 Alice 和 Bob 都发挥出最佳水平,返回 Alice 可以得到的最大数量的石头。
@@ -39,7 +39,8 @@ tags:
输入:piles = [2,7,9,4,4] 输出:10 -解释:如果一开始Alice取了一堆,Bob取了两堆,然后Alice再取两堆。爱丽丝可以得到2 + 4 + 4 = 10堆。如果Alice一开始拿走了两堆,那么Bob可以拿走剩下的三堆。在这种情况下,Alice得到2 + 7 = 9堆。返回10,因为它更大。 +解释:如果一开始 Alice 取了一堆,Bob 取了两堆,然后 Alice 再取两堆。Alice 可以得到 2 + 4 + 4 = 10 堆。 +如果 Alice 一开始拿走了两堆,那么 Bob 可以拿走剩下的三堆。在这种情况下,Alice 得到 2 + 7 = 9 堆。返回 10,因为它更大。
示例 2:
diff --git a/solution/1100-1199/1140.Stone Game II/README_EN.md b/solution/1100-1199/1140.Stone Game II/README_EN.md index 4a3a5d416d9db..c7719ada5b0cc 100644 --- a/solution/1100-1199/1140.Stone Game II/README_EN.md +++ b/solution/1100-1199/1140.Stone Game II/README_EN.md @@ -22,31 +22,41 @@ tags: -Alice and Bob continue their games with piles of stones. There are a number of piles arranged in a row, and each pile has a positive integer number of stones piles[i]
. The objective of the game is to end with the most stones.
Alice and Bob continue their games with piles of stones. There are a number of piles arranged in a row, and each pile has a positive integer number of stones piles[i]
. The objective of the game is to end with the most stones.
Alice and Bob take turns, with Alice starting first. Initially, M = 1
.
Alice and Bob take turns, with Alice starting first.
-On each player's turn, that player can take all the stones in the first X
remaining piles, where 1 <= X <= 2M
. Then, we set M = max(M, X)
.
On each player's turn, that player can take all the stones in the first X
remaining piles, where 1 <= X <= 2M
. Then, we set M = max(M, X)
. Initially, M = 1.
The game continues until all the stones have been taken.
-Assuming Alice and Bob play optimally, return the maximum number of stones Alice can get.
+Assuming Alice and Bob play optimally, return the maximum number of stones Alice can get.
Example 1:
--Input: piles = [2,7,9,4,4] -Output: 10 -Explanation: If Alice takes one pile at the beginning, Bob takes two piles, then Alice takes 2 piles again. Alice can get 2 + 4 + 4 = 10 piles in total. If Alice takes two piles at the beginning, then Bob can take all three piles left. In this case, Alice get 2 + 7 = 9 piles in total. So we return 10 since it's larger. -+
Input: piles = [2,7,9,4,4]
+ +Output: 10
+ +Explanation:
+ +2 + 4 + 4 = 10
stones in total.2 + 7 = 9
stones in total.So we return 10 since it's larger.
+Example 2:
--Input: piles = [1,2,3,4,5,100] -Output: 104 -+
Input: piles = [1,2,3,4,5,100]
+ +Output: 104
+
Constraints:
diff --git a/solution/1100-1199/1152.Analyze User Website Visit Pattern/README.md b/solution/1100-1199/1152.Analyze User Website Visit Pattern/README.md index fb70dbd269d87..5b959a1bb55b8 100644 --- a/solution/1100-1199/1152.Analyze User Website Visit Pattern/README.md +++ b/solution/1100-1199/1152.Analyze User Website Visit Pattern/README.md @@ -38,23 +38,25 @@ tags:返回 得分 最大的 访问模式 。如果有多个访问模式具有相同的最大分数,则返回字典序最小的。
+请注意,模式中的网站不需要连续访问,只需按照模式中出现的顺序访问即可。
+-
示例 1:
+示例 1:
输入:username = ["joe","joe","joe","james","james","james","james","mary","mary","mary"], timestamp = [1,2,3,4,5,6,7,8,9,10], website = ["home","about","career","home","cart","maps","home","home","about","career"] 输出:["home","about","career"] 解释:本例中的元组是: -["joe","home",1],["joe","about",2],["joe","career",3],["james","home",4],["james","cart",5],["james","maps",6],["james","home",7],["mary","home",8],["mary","about",9], and ["mary","career",10]. -模式("home", "about", "career") has score 2 (joe and mary). -模式("home", "cart", "maps") 的得分为 1 (james). +["joe","home",1],["joe","about",2],["joe","career",3],["james","home",4],["james","cart",5],["james","maps",6],["james","home",7],["mary","home",8],["mary","about",9] 和 ["mary","career",10]。 +模式 ("home", "about", "career") 的得分为 2(joe 和 mary)。 +模式 ("home", "cart", "maps") 的得分为 1 (james). 模式 ("home", "cart", "home") 的得分为 1 (james). 模式 ("home", "maps", "home") 的得分为 1 (james). 模式 ("cart", "maps", "home") 的得分为 1 (james). -模式 ("home", "home", "home") 的得分为 0(没有用户访问过home 3次)。+模式 ("home", "home", "home") 的得分为 0(没有用户访问过 home 3次)。 -
示例 2:
+示例 2:
输入: username = ["ua","ua","ua","ub","ub","ub"], timestamp = [1,2,3,4,5,6], website = ["a","b","a","a","b","c"] diff --git a/solution/1200-1299/1207.Unique Number of Occurrences/README.md b/solution/1200-1299/1207.Unique Number of Occurrences/README.md index 726c5c2fcc85c..955323c79d6b1 100644 --- a/solution/1200-1299/1207.Unique Number of Occurrences/README.md +++ b/solution/1200-1299/1207.Unique Number of Occurrences/README.md @@ -19,27 +19,28 @@ tags: -给你一个整数数组
- -arr
,请你帮忙统计数组中每个数的出现次数。如果每个数的出现次数都是独一无二的,就返回
+true
;否则返回false
。给你一个整数数组
arr
,如果每个数的出现次数都是独一无二的,就返回true
;否则返回false
。
示例 1:
-输入:arr = [1,2,2,1,1,3] ++输入:arr = [1,2,2,1,1,3] 输出:true 解释:在该数组中,1 出现了 3 次,2 出现了 2 次,3 只出现了 1 次。没有两个数的出现次数相同。示例 2:
-输入:arr = [1,2] ++输入:arr = [1,2] 输出:false示例 3:
-输入:arr = [-3,0,1,-3,1,1,1,-3,10,0] ++输入:arr = [-3,0,1,-3,1,1,1,-3,10,0] 输出:truediff --git a/solution/1300-1399/1330.Reverse Subarray To Maximize Array Value/README.md b/solution/1300-1399/1330.Reverse Subarray To Maximize Array Value/README.md index c7b95f909d7d2..969f32e7d746a 100644 --- a/solution/1300-1399/1330.Reverse Subarray To Maximize Array Value/README.md +++ b/solution/1300-1399/1330.Reverse Subarray To Maximize Array Value/README.md @@ -30,14 +30,16 @@ tags:示例 1:
-输入:nums = [2,3,1,5,4] ++输入:nums = [2,3,1,5,4] 输出:10 解释:通过翻转子数组 [3,1,5] ,数组变成 [2,5,1,3,4] ,数组值为 10 。示例 2:
-输入:nums = [2,4,9,24,2,1,10] ++输入:nums = [2,4,9,24,2,1,10] 输出:68@@ -46,8 +48,9 @@ tags:提示:
1 <= nums.length <= 3*10^4
-10^5 <= nums[i] <= 10^5
2 <= nums.length <= 3*104
-105 <= nums[i] <= 105
表:MovieRating
You are given a string s
. Reorder the string using the following algorithm:
s
and append it to the result.s
which is greater than the last appended character to the result and append it.s
and append it to the result.s
which is smaller than the last appended character to the result and append it.s
.s
and append it to the result.s
that is greater than the last appended character, and append it to the result.s
and append it to the result.s
that is smaller than the last appended character, and append it to the result.s
have been removed.In each step, If the smallest or the largest character appears more than once you can choose any occurrence and append it to the result.
+If the smallest or largest character appears more than once, you may choose any occurrence to append to the result.
-Return the result string after sorting s
with this algorithm.
Return the resulting string after reordering s
using this algorithm.
Example 1:
diff --git a/solution/1400-1499/1432.Max Difference You Can Get From Changing an Integer/README_EN.md b/solution/1400-1499/1432.Max Difference You Can Get From Changing an Integer/README_EN.md index 5b5b3188c27dd..8b054be5c0d7b 100644 --- a/solution/1400-1499/1432.Max Difference You Can Get From Changing an Integer/README_EN.md +++ b/solution/1400-1499/1432.Max Difference You Can Get From Changing an Integer/README_EN.md @@ -57,7 +57,7 @@ We have now a = 9 and b = 1 and max difference = 8Constraints:
1 <= num <= 10
81 <= num <= 108
-
示例 1:
+示例 1:
输入:numCourses = 2, prerequisites = [[1,0]], queries = [[0,1],[1,0]] 输出:[false,true] -解释:课程 0 不是课程 1 的先修课程,但课程 1 是课程 0 的先修课程。 +解释:[1, 0] 数对表示在你上课程 0 之前必须先上课程 1。 +课程 0 不是课程 1 的先修课程,但课程 1 是课程 0 的先修课程。-
示例 2:
+示例 2:
输入:numCourses = 2, prerequisites = [], queries = [[1,0],[0,1]] @@ -53,7 +54,7 @@ tags: 解释:没有先修课程对,所以每门课程之间是独立的。-
示例 3:
+示例 3:
2 <= numCourses <= 100
0 <= prerequisites.length <= (numCourses * (numCourses - 1) / 2)
prerequisites[i].length == 2
0 <= ai, bi <= n - 1
0 <= ai, bi <= numCourses - 1
ai != bi
[ai, bi]
都 不同1 <= queries.length <= 104
0 <= ui, vi <= n - 1
0 <= ui, vi <= numCourses - 1
ui != vi
If two robots collide, the robot with lower health is removed from the line, and the health of the other robot decreases by one. The surviving robot continues in the same direction it was going. If both robots have the same health, they are both removed from the line.
-Your task is to determine the health of the robots that survive the collisions, in the same order that the robots were given, i.e. final heath of robot 1 (if survived), final health of robot 2 (if survived), and so on. If there are no survivors, return an empty array.
+Your task is to determine the health of the robots that survive the collisions, in the same order that the robots were given, i.e. final health of robot 1 (if survived), final health of robot 2 (if survived), and so on. If there are no survivors, return an empty array.
Return an array containing the health of the remaining robots (in the order they were given in the input), after no further collisions can occur.
diff --git a/solution/2900-2999/2967.Minimum Cost to Make Array Equalindromic/README.md b/solution/2900-2999/2967.Minimum Cost to Make Array Equalindromic/README.md index b1518e39a5b21..a5988bd60cbe9 100644 --- a/solution/2900-2999/2967.Minimum Cost to Make Array Equalindromic/README.md +++ b/solution/2900-2999/2967.Minimum Cost to Make Array Equalindromic/README.md @@ -8,6 +8,7 @@ tags: - 贪心 - 数组 - 数学 + - 二分查找 - 排序 --- diff --git a/solution/2900-2999/2967.Minimum Cost to Make Array Equalindromic/README_EN.md b/solution/2900-2999/2967.Minimum Cost to Make Array Equalindromic/README_EN.md index 844930b3fc80a..91acd5c5a9d83 100644 --- a/solution/2900-2999/2967.Minimum Cost to Make Array Equalindromic/README_EN.md +++ b/solution/2900-2999/2967.Minimum Cost to Make Array Equalindromic/README_EN.md @@ -8,6 +8,7 @@ tags: - Greedy - Array - Math + - Binary Search - Sorting --- diff --git a/solution/3100-3199/3104.Find Longest Self-Contained Substring/README.md b/solution/3100-3199/3104.Find Longest Self-Contained Substring/README.md index b7bc91dac3183..6ea2ba2e5b9f1 100644 --- a/solution/3100-3199/3104.Find Longest Self-Contained Substring/README.md +++ b/solution/3100-3199/3104.Find Longest Self-Contained Substring/README.md @@ -11,7 +11,7 @@ tags: -# [3104. Find Longest Self-Contained Substring 🔒](https://leetcode.cn/problems/find-longest-self-contained-substring) +# [3104. 查找最长的自包含子串 🔒](https://leetcode.cn/problems/find-longest-self-contained-substring) [English Version](/solution/3100-3199/3104.Find%20Longest%20Self-Contained%20Substring/README_EN.md) @@ -19,52 +19,54 @@ tags: -Given a string s
, your task is to find the length of the longest self-contained substring of s
.
给定字符串 s
,你需要找到 s
的 最长自包含 子串 的长度。
A substring t
of a string s
is called self-contained if t != s
and for every character in t
, it doesn't exist in the rest of s
.
如果 s
的一个子串 t
满足 t != s
且 t
中的每一个字符在 s
的剩余部分都不存在,则被称为是 自包含 的。
Return the length of the longest self-contained substring of s
if it exists, otherwise, return -1.
如果存在 s
的最长自包含子串,返回它的长度,否则返回 -1。
-
Example 1:
+ +示例 1:
Input: s = "abba"
+输入:s = "abba"
-Output: 2
+输出:2
-Explanation:
-Let's check the substring "bb"
. You can see that no other "b"
is outside of this substring. Hence the answer is 2.
解释:
+让我们检查子串 "bb"
。你可以发现子串外没有其它 "b"
。因此答案为 2。
Example 2:
+示例 2:
Input: s = "abab"
+输入:s = "abab"
-Output: -1
+输出:-1
-Explanation:
-Every substring we choose does not satisfy the described property (there is some character which is inside and outside of that substring). So the answer would be -1.
解释:
+我们选择的每一个子串都不满足描述的特点(子串内外包含有一些字母)。所以答案是 -1。
Example 3:
+示例 3:
Input: s = "abacd"
+输入:s = "abacd"
-Output: 4
+输出:4
-Explanation:
-Let's check the substring "abac"
. There is only one character outside of this substring and that is "d"
. There is no "d"
inside the chosen substring, so it satisfies the condition and the answer is 4.
解释:
+让我们检查子串 "abac"
。子串之外只有一个字母 "d"
。子串内没有 "d"
,所以它满足条件并且答案为 4。
-
Constraints:
+ +提示:
2 <= s.length <= 5 * 104
s
consists only of lowercase English letters.s
只包含小写英文字母。Given an array perm
of length n
which is a permutation of [1, 2, ..., n]
, return the index of perm
in the lexicographically sorted array of all of the permutations of [1, 2, ..., n]
.
给定一个长度为 n
的数组 perm
,它是 [1, 2, ..., n]
的一个排列,返回 [1, 2, ..., n]
的所有排列的字典序数组中 perm
的下标。
Since the answer may be very large, return it modulo 109 + 7
.
由于答案可能非常大,返回值对 109 + 7
取模。
-
Example 1:
+ +示例 1:
Input: perm = [1,2]
+输入:perm = [1,2]
-Output: 0
+输出:0
-Explanation:
+解释:
-There are only two permutations in the following order:
+按以下顺序只有 2 种排列:
[1,2]
, [2,1]
-And [1,2]
is at index 0.
[1,2]
在下标 0。
Example 2:
+示例 2:
Input: perm = [3,1,2]
+输入:perm = [3,1,2]
-Output: 4
+输出:4
-Explanation:
+解释:
-There are only six permutations in the following order:
+按以下顺序只有 6 种排列:
[1,2,3]
, [1,3,2]
, [2,1,3]
, [2,3,1]
, [3,1,2]
, [3,2,1]
-And [3,1,2]
is at index 4.
[3,1,2]
在下标 4。
-
Constraints:
+ +提示:
1 <= n == perm.length <= 105
perm
is a permutation of [1, 2, ..., n]
.perm
是 [1, 2, ..., n]
的一个排列。Table: Purchases
表:Purchases
+---------------+------+ @@ -26,12 +26,12 @@ tags: | purchase_date | date | | amount_spend | int | +---------------+------+ -(user_id, purchase_date, amount_spend) is the primary key (combination of columns with unique values) for this table. -purchase_date will range from November 1, 2023, to November 30, 2023, inclusive of both dates. -Each row contains user_id, purchase_date, and amount_spend. +(user_id, purchase_date, amount_spend) 是该表的主键(具有唯一值的列)。 +purchase_date 的范围从 2023 年 11 月 1 日到 2023 年 11 月 30 日,并包括这两个日期。 +每一行包含 user_id, purchase_date,和 amount_spend。-
Table: Users
表:Users
+-------------+------+ @@ -40,24 +40,25 @@ Each row contains user_id, purchase_date, and amount_spend. | user_id | int | | membership | enum | +-------------+------+ -user_id is the primary key for this table. -membership is an ENUM (category) type of ('Standard', 'Premium', 'VIP'). -Each row of this table indicates the user_id, membership type. +user_id 是这张表的主键。 +membership 是 ('Standard', 'Premium', 'VIP') 的枚举类型。 +这张表的每一行表示 user_id 和会员类型。-
Write a solution to calculate the total spending by Premium
and VIP
members on each Friday of every week in November 2023. If there are no purchases on a particular Friday by Premium
or VIP
members, it should be considered as 0
.
编写一个解决方案来计算 Premium
和 VIP
会员在 2023 年 11 月 每周的周五 的 总花费。如果某个周五没有 Premium
或 VIP
会员购买,把它当作 0
。
Return the result table ordered by week of the month, and membership
in ascending order.
按照每月的周次序 升序 排列结果表,然后以 membership
升序 排序。
The result format is in the following example.
+结果格式如下所示。
-
Example:
+ +示例:
Input:
+输入:
-Purchases table:
+Purchases 表:
+---------+---------------+--------------+ @@ -74,7 +75,7 @@ Each row of this table indicates the user_id, membership type. +---------+---------------+--------------+-
Users table:
+Users 表:
+---------+------------+ @@ -91,7 +92,7 @@ Each row of this table indicates the user_id, membership type. +---------+------------+-
Output:
+输出:
+---------------+-------------+--------------+ @@ -108,16 +109,16 @@ Each row of this table indicates the user_id, membership type. +---------------+-------------+--------------+-
Explanation:
+解释:
Note: The output table is ordered by week_of_month and membership in ascending order.
+注意:输出表以 week_of_month 和 membership 升序排序。
Explanation:
Note: Output table is sorted by type, duration, and first_name in descending order.
diff --git a/solution/3100-3199/3134.Find the Median of the Uniqueness Array/README.md b/solution/3100-3199/3134.Find the Median of the Uniqueness Array/README.md index 7970ae1d3e7ef..c1db9a58eee8f 100644 --- a/solution/3100-3199/3134.Find the Median of the Uniqueness Array/README.md +++ b/solution/3100-3199/3134.Find the Median of the Uniqueness Array/README.md @@ -21,7 +21,7 @@ tags: -给你一个整数数组 nums
。数组 nums
的 唯一性数组 是一个按元素从小到大排序的数组,包含了 nums
的所有非空子数组中不同元素的个数。
给你一个整数数组 nums
。数组 nums
的 唯一性数组 是一个按元素从小到大排序的数组,包含了 nums
的所有非空 子数组 中不同元素的个数。
换句话说,这是由所有 0 <= i <= j < nums.length
的 distinct(nums[i..j])
组成的递增数组。
"c"
在 s
中的位置与在 t
中的位置之差的绝对值。即,s
和 t
的排列差等于 |0 - 1| + |2 - 2| + |1 - 0| = 2
。
即,s
和 t
的排列差等于 |0 - 1| + |1 - 0| + |2 - 2| = 2
。
示例 2:
diff --git a/solution/3100-3199/3146.Permutation Difference between Two Strings/README_EN.md b/solution/3100-3199/3146.Permutation Difference between Two Strings/README_EN.md index 95ae78b3ca3c3..a0116f56c4cf9 100644 --- a/solution/3100-3199/3146.Permutation Difference between Two Strings/README_EN.md +++ b/solution/3100-3199/3146.Permutation Difference between Two Strings/README_EN.md @@ -43,7 +43,7 @@ tags:"c"
in s
and the index of the occurrence of "c"
in t
.That is, the permutation difference between s
and t
is equal to |0 - 1| + |2 - 2| + |1 - 0| = 2
.
That is, the permutation difference between s
and t
is equal to |0 - 1| + |1 - 0| + |2 - 2| = 2
.
Example 2:
diff --git a/solution/3100-3199/3178.Find the Child Who Has the Ball After K Seconds/README.md b/solution/3100-3199/3178.Find the Child Who Has the Ball After K Seconds/README.md index 99adfd76fec09..8ab09cd3319ff 100644 --- a/solution/3100-3199/3178.Find the Child Who Has the Ball After K Seconds/README.md +++ b/solution/3100-3199/3178.Find the Child Who Has the Ball After K Seconds/README.md @@ -157,6 +157,10 @@ tags:1 <= k <= 50
+ +
注意:此问题与 2582. 递枕头 一致。
+ ## 解法 diff --git a/solution/3200-3299/3263.Convert Doubly Linked List to Array I/README.md b/solution/3200-3299/3263.Convert Doubly Linked List to Array I/README.md index 25da724d491c6..319f2f312e85c 100644 --- a/solution/3200-3299/3263.Convert Doubly Linked List to Array I/README.md +++ b/solution/3200-3299/3263.Convert Doubly Linked List to Array I/README.md @@ -2,6 +2,10 @@ comments: true difficulty: 简单 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3263.Convert%20Doubly%20Linked%20List%20to%20Array%20I/README.md +tags: + - 数组 + - 链表 + - 双向链表 --- diff --git a/solution/3200-3299/3263.Convert Doubly Linked List to Array I/README_EN.md b/solution/3200-3299/3263.Convert Doubly Linked List to Array I/README_EN.md index 88319b5e7b123..4bd707425088e 100644 --- a/solution/3200-3299/3263.Convert Doubly Linked List to Array I/README_EN.md +++ b/solution/3200-3299/3263.Convert Doubly Linked List to Array I/README_EN.md @@ -2,6 +2,10 @@ comments: true difficulty: Easy edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3263.Convert%20Doubly%20Linked%20List%20to%20Array%20I/README_EN.md +tags: + - Array + - Linked List + - Doubly-Linked List --- diff --git a/solution/3200-3299/3264.Final Array State After K Multiplication Operations I/README.md b/solution/3200-3299/3264.Final Array State After K Multiplication Operations I/README.md index 63f3dfd3d839f..914a955d2916d 100644 --- a/solution/3200-3299/3264.Final Array State After K Multiplication Operations I/README.md +++ b/solution/3200-3299/3264.Final Array State After K Multiplication Operations I/README.md @@ -2,6 +2,11 @@ comments: true difficulty: 简单 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3264.Final%20Array%20State%20After%20K%20Multiplication%20Operations%20I/README.md +tags: + - 数组 + - 数学 + - 模拟 + - 堆(优先队列) --- diff --git a/solution/3200-3299/3264.Final Array State After K Multiplication Operations I/README_EN.md b/solution/3200-3299/3264.Final Array State After K Multiplication Operations I/README_EN.md index bd93fdade75f7..32619fb63aee2 100644 --- a/solution/3200-3299/3264.Final Array State After K Multiplication Operations I/README_EN.md +++ b/solution/3200-3299/3264.Final Array State After K Multiplication Operations I/README_EN.md @@ -2,6 +2,11 @@ comments: true difficulty: Easy edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3264.Final%20Array%20State%20After%20K%20Multiplication%20Operations%20I/README_EN.md +tags: + - Array + - Math + - Simulation + - Heap (Priority Queue) --- diff --git a/solution/3200-3299/3265.Count Almost Equal Pairs I/README.md b/solution/3200-3299/3265.Count Almost Equal Pairs I/README.md index e092294652508..d323d0224e1dc 100644 --- a/solution/3200-3299/3265.Count Almost Equal Pairs I/README.md +++ b/solution/3200-3299/3265.Count Almost Equal Pairs I/README.md @@ -2,6 +2,12 @@ comments: true difficulty: 中等 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3265.Count%20Almost%20Equal%20Pairs%20I/README.md +tags: + - 数组 + - 哈希表 + - 计数 + - 枚举 + - 排序 --- @@ -66,7 +72,7 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3265.Co解释:
-我们无法通过交换 123
或者 321
中的两个数位得到另一个数。
我们无法通过交换 123 或者 321 中的两个数位得到另一个数。
diff --git a/solution/3200-3299/3265.Count Almost Equal Pairs I/README_EN.md b/solution/3200-3299/3265.Count Almost Equal Pairs I/README_EN.md index bf19be12d55e6..9889eb8bca69a 100644 --- a/solution/3200-3299/3265.Count Almost Equal Pairs I/README_EN.md +++ b/solution/3200-3299/3265.Count Almost Equal Pairs I/README_EN.md @@ -2,6 +2,12 @@ comments: true difficulty: Medium edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3265.Count%20Almost%20Equal%20Pairs%20I/README_EN.md +tags: + - Array + - Hash Table + - Counting + - Enumeration + - Sorting --- @@ -65,7 +71,7 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3265.Co
Explanation:
-We cannot swap any two digits of 123
or 231
to reach the other.
We cannot swap any two digits of 123 or 231 to reach the other.
diff --git a/solution/3200-3299/3266.Final Array State After K Multiplication Operations II/README.md b/solution/3200-3299/3266.Final Array State After K Multiplication Operations II/README.md index 3c34aba5086af..880dee8e29e51 100644 --- a/solution/3200-3299/3266.Final Array State After K Multiplication Operations II/README.md +++ b/solution/3200-3299/3266.Final Array State After K Multiplication Operations II/README.md @@ -2,6 +2,10 @@ comments: true difficulty: 困难 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3266.Final%20Array%20State%20After%20K%20Multiplication%20Operations%20II/README.md +tags: + - 数组 + - 模拟 + - 堆(优先队列) --- diff --git a/solution/3200-3299/3266.Final Array State After K Multiplication Operations II/README_EN.md b/solution/3200-3299/3266.Final Array State After K Multiplication Operations II/README_EN.md index d994bda463e0f..72c85e8af7494 100644 --- a/solution/3200-3299/3266.Final Array State After K Multiplication Operations II/README_EN.md +++ b/solution/3200-3299/3266.Final Array State After K Multiplication Operations II/README_EN.md @@ -2,6 +2,10 @@ comments: true difficulty: Hard edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3266.Final%20Array%20State%20After%20K%20Multiplication%20Operations%20II/README_EN.md +tags: + - Array + - Simulation + - Heap (Priority Queue) --- diff --git a/solution/3200-3299/3267.Count Almost Equal Pairs II/README.md b/solution/3200-3299/3267.Count Almost Equal Pairs II/README.md index f9c8bca7706f6..d01441c06554d 100644 --- a/solution/3200-3299/3267.Count Almost Equal Pairs II/README.md +++ b/solution/3200-3299/3267.Count Almost Equal Pairs II/README.md @@ -2,6 +2,12 @@ comments: true difficulty: 困难 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3267.Count%20Almost%20Equal%20Pairs%20II/README.md +tags: + - 数组 + - 哈希表 + - 计数 + - 枚举 + - 排序 --- diff --git a/solution/3200-3299/3267.Count Almost Equal Pairs II/README_EN.md b/solution/3200-3299/3267.Count Almost Equal Pairs II/README_EN.md index d7e7e304dd3f3..4d02f2f9bda46 100644 --- a/solution/3200-3299/3267.Count Almost Equal Pairs II/README_EN.md +++ b/solution/3200-3299/3267.Count Almost Equal Pairs II/README_EN.md @@ -2,6 +2,12 @@ comments: true difficulty: Hard edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3267.Count%20Almost%20Equal%20Pairs%20II/README_EN.md +tags: + - Array + - Hash Table + - Counting + - Enumeration + - Sorting --- diff --git a/solution/3200-3299/3268.Find Overlapping Shifts II/README.md b/solution/3200-3299/3268.Find Overlapping Shifts II/README.md index 66118275f3916..86cc958268c18 100644 --- a/solution/3200-3299/3268.Find Overlapping Shifts II/README.md +++ b/solution/3200-3299/3268.Find Overlapping Shifts II/README.md @@ -8,7 +8,7 @@ tags: -# [3268. Find Overlapping Shifts II 🔒](https://leetcode.cn/problems/find-overlapping-shifts-ii) +# [3268. 查找重叠的班次 II 🔒](https://leetcode.cn/problems/find-overlapping-shifts-ii) [English Version](/solution/3200-3299/3268.Find%20Overlapping%20Shifts%20II/README_EN.md) @@ -16,7 +16,7 @@ tags: -
Table: EmployeeShifts
表:EmployeeShifts
+------------------+----------+ @@ -26,30 +26,31 @@ tags: | start_time | datetime | | end_time | datetime | +------------------+----------+ -(employee_id, start_time) is the unique key for this table. -This table contains information about the shifts worked by employees, including the start time, and end time. +(employee_id, start_time) 是此表的唯一主键。 +这张表包含员工的排班工作,包括特定日期的开始和结束时间。-
Write a solution to analyze overlapping shifts for each employee. Two shifts are considered overlapping if they occur on the same date and one shift's end_time
is later than another shift's start_time
.
编写一个解决方案来为每个员工分析重叠排班。如果一个排班的 end_time
比另一个排班的 start_time
更晚 则认为两个排班重叠。
For each employee, calculate the following:
+对于 每个员工,计算如下内容:
Return the result table ordered by employee_id
in ascending order.
返回结果表以 employee_id
升序 排序。
The query result format is in the following example.
+查询结果格式如下所示。
-
Example:
+ +示例:
Input:
+输入:
-EmployeeShifts
table:
EmployeeShifts
表:
+-------------+---------------------+---------------------+ @@ -64,7 +65,7 @@ This table contains information about the shifts worked by employees, including +-------------+---------------------+---------------------+-
Output:
+输出:
+-------------+---------------------------+------------------------+ @@ -76,26 +77,26 @@ This table contains information about the shifts worked by employees, including +-------------+---------------------------+------------------------+-
Explanation:
+解释:
The output table contains the employee_id, the maximum number of simultaneous overlaps, and the total overlap duration in minutes for each employee, ordered by employee_id in ascending order.
+输出表包含 employee_id,同时重叠排班的最大数量,以及每位员工的重叠班次总持续时间(分钟),以 employee_id 升序排序。
Given 2 integer arrays nums1
and nums2
consisting only of 0 and 1, your task is to calculate the minimum possible largest number in arrays nums1
and nums2
, after doing the following.
Replace every 0 with an even positive integer and every 1 with an odd positive integer. After replacement, both arrays should be increasing and each integer should be used at most once.
+ +Return the minimum possible largest number after applying the changes.
+ ++
Example 1:
+ +Input: nums1 = [], nums2 = [1,0,1,1]
+ +Output: 5
+ +Explanation:
+ +After replacing, nums1 = []
, and nums2 = [1, 2, 3, 5]
.
Example 2:
+ +Input: nums1 = [0,1,0,1], nums2 = [1,0,0,1]
+ +Output: 9
+ +Explanation:
+ +One way to replace, having 9 as the largest element is nums1 = [2, 3, 8, 9]
, and nums2 = [1, 4, 6, 7]
.
Example 3:
+ +Input: nums1 = [0,1,0,0,1], nums2 = [0,0,0,1]
+ +Output: 13
+ +Explanation:
+ +One way to replace, having 13 as the largest element is nums1 = [2, 3, 4, 6, 7]
, and nums2 = [8, 10, 12, 13]
.
+
Constraints:
+ +0 <= nums1.length <= 1000
1 <= nums2.length <= 1000
nums1
and nums2
consist only of 0 and 1.Given 2 integer arrays nums1
and nums2
consisting only of 0 and 1, your task is to calculate the minimum possible largest number in arrays nums1
and nums2
, after doing the following.
Replace every 0 with an even positive integer and every 1 with an odd positive integer. After replacement, both arrays should be increasing and each integer should be used at most once.
+ +Return the minimum possible largest number after applying the changes.
+ ++
Example 1:
+ +Input: nums1 = [], nums2 = [1,0,1,1]
+ +Output: 5
+ +Explanation:
+ +After replacing, nums1 = []
, and nums2 = [1, 2, 3, 5]
.
Example 2:
+ +Input: nums1 = [0,1,0,1], nums2 = [1,0,0,1]
+ +Output: 9
+ +Explanation:
+ +One way to replace, having 9 as the largest element is nums1 = [2, 3, 8, 9]
, and nums2 = [1, 4, 6, 7]
.
Example 3:
+ +Input: nums1 = [0,1,0,0,1], nums2 = [0,0,0,1]
+ +Output: 13
+ +Explanation:
+ +One way to replace, having 13 as the largest element is nums1 = [2, 3, 4, 6, 7]
, and nums2 = [8, 10, 12, 13]
.
+
Constraints:
+ +0 <= nums1.length <= 1000
1 <= nums2.length <= 1000
nums1
and nums2
consist only of 0 and 1.