diff --git a/solution/0200-0299/0277.Find the Celebrity/README_EN.md b/solution/0200-0299/0277.Find the Celebrity/README_EN.md index 56be8c2410d0a..b69073887df63 100644 --- a/solution/0200-0299/0277.Find the Celebrity/README_EN.md +++ b/solution/0200-0299/0277.Find the Celebrity/README_EN.md @@ -22,10 +22,12 @@ tags:
Now you want to find out who the celebrity is or verify that there is not one. You are only allowed to ask questions like: "Hi, A. Do you know B?" to get information about whether A knows B. You need to find out the celebrity (or verify there is not one) by asking as few questions as possible (in the asymptotic sense).
-You are given a helper function bool knows(a, b)
that tells you whether a
knows b
. Implement a function int findCelebrity(n)
. There will be exactly one celebrity if they are at the party.
You are given an integer n
and a helper function bool knows(a, b)
that tells you whether a
knows b
. Implement a function int findCelebrity(n)
. There will be exactly one celebrity if they are at the party.
Return the celebrity's label if there is a celebrity at the party. If there is no celebrity, return -1
.
Note that the n x n
2D array graph
given as input is not directly available to you, and instead only accessible through the helper function knows
. graph[i][j] == 1
represents person i
knows person j
, wherease graph[i][j] == 0
represents person j
does not know person i
.
Example 1:
1 <= nestedList.length <= 50
[-100, 100]
50
1 <= nestedList.length <= 50
[-100, 100]
.50
.一个 n x n
的二维网络 board
仅由 0
和 1
组成 。每次移动,你能任意交换两列或是两行的位置。
一个 n x n
的二维网络 board
仅由 0
和 1
组成 。每次移动,你能交换任意两列或是两行的位置。
返回 将这个矩阵变为 “棋盘” 所需的最小移动次数 。如果不存在可行的变换,输出 -1
。
diff --git a/solution/1600-1699/1683.Invalid Tweets/README_EN.md b/solution/1600-1699/1683.Invalid Tweets/README_EN.md index 322780b87a293..9b40b39e72e7a 100644 --- a/solution/1600-1699/1683.Invalid Tweets/README_EN.md +++ b/solution/1600-1699/1683.Invalid Tweets/README_EN.md @@ -26,6 +26,7 @@ tags: | content | varchar | +----------------+---------+ tweet_id is the primary key (column with unique values) for this table. +content consists of characters on an American Keyboard, and no other special characters. This table contains all the tweets in a social media app. diff --git a/solution/1800-1899/1861.Rotating the Box/README.md b/solution/1800-1899/1861.Rotating the Box/README.md index d8b5644af7adb..582727d21134d 100644 --- a/solution/1800-1899/1861.Rotating the Box/README.md +++ b/solution/1800-1899/1861.Rotating the Box/README.md @@ -20,68 +20,71 @@ tags: -
给你一个 m x n
的字符矩阵 box
,它表示一个箱子的侧视图。箱子的每一个格子可能为:
给你一个 m x n
的字符矩阵 boxGrid
,它表示一个箱子的侧视图。箱子的每一个格子可能为:
'#'
表示石头'*'
表示固定的障碍物'.'
表示空位置'#'
表示石头'*'
表示固定的障碍物'.'
表示空位置这个箱子被 顺时针旋转 90 度 ,由于重力原因,部分石头的位置会发生改变。每个石头会垂直掉落,直到它遇到障碍物,另一个石头或者箱子的底部。重力 不会 影响障碍物的位置,同时箱子旋转不会产生惯性 ,也就是说石头的水平位置不会发生改变。
+这个箱子被 顺时针旋转 90 度 ,由于重力原因,部分石头的位置会发生改变。每个石头会垂直掉落,直到它遇到障碍物,另一个石头或者箱子的底部。重力 不会 影响障碍物的位置,同时箱子旋转不会产生惯性 ,也就是说石头的水平位置不会发生改变。
-题目保证初始时 box
中的石头要么在一个障碍物上,要么在另一个石头上,要么在箱子的底部。
题目保证初始时 boxGrid
中的石头要么在一个障碍物上,要么在另一个石头上,要么在箱子的底部。
请你返回一个 n x m
的矩阵,表示按照上述旋转后,箱子内的结果。
请你返回一个 n x m
的矩阵,表示按照上述旋转后,箱子内的结果。
+
示例 1:
-输入:box = [["#",".","#"]] ++输入:box = [["#",".","#"]] 输出:[["."], - ["#"], - ["#"]] + ["#"], + ["#"]]示例 2:
-+
-
输入:box = [["#",".","*","."], - ["#","#","*","."]] ++输入:box = [["#",".","*","."], + ["#","#","*","."]] 输出:[["#","."], - ["#","#"], - ["*","*"], - [".","."]] + ["#","#"], + ["*","*"], + [".","."]]示例 3:
-+
-
输入:box = [["#","#","*",".","*","."], - ["#","#","#","*",".","."], - ["#","#","#",".","#","."]] ++输入:box = [["#","#","*",".","*","."], + ["#","#","#","*",".","."], + ["#","#","#",".","#","."]] 输出:[[".","#","#"], - [".","#","#"], - ["#","#","*"], - ["#","*","."], - ["#",".","*"], - ["#",".","."]] + [".","#","#"], + ["#","#","*"], + ["#","*","."], + ["#",".","*"], + ["#",".","."]]-+
提示:
m == box.length
n == box[i].length
m == boxGrid.length
n == boxGrid[i].length
1 <= m, n <= 500
box[i][j]
只可能是 '#'
,'*'
或者 '.'
。boxGrid[i][j]
只可能是 '#'
,'*'
或者 '.'
。You are given an m x n
matrix of characters box
representing a side-view of a box. Each cell of the box is one of the following:
You are given an m x n
matrix of characters boxGrid
representing a side-view of a box. Each cell of the box is one of the following:
'#'
'*'
'.'
'#'
'*'
'.'
The box is rotated 90 degrees clockwise, causing some of the stones to fall due to gravity. Each stone falls down until it lands on an obstacle, another stone, or the bottom of the box. Gravity does not affect the obstacles' positions, and the inertia from the box's rotation does not affect the stones' horizontal positions.
-It is guaranteed that each stone in box
rests on an obstacle, another stone, or the bottom of the box.
It is guaranteed that each stone in boxGrid
rests on an obstacle, another stone, or the bottom of the box.
Return an n x m
matrix representing the box after the rotation described above.
-
Example 1:
- -Input: box = [["#",".","#"]] - +Input: boxGrid = [["#",".","#"]] Output: [["."], - ["#"], - ["#"]] -
Example 2:
@@ -61,19 +51,12 @@ tags:- -Input: box = [["#",".","*","."], - +Input: boxGrid = [["#",".","*","."], ["#","#","*","."]] - Output: [["#","."], - ["#","#"], - ["*","*"], - [".","."]] -
Example 3:
@@ -81,41 +64,25 @@ tags:- -Input: box = [["#","#","*",".","*","."], - +Input: boxGrid = [["#","#","*",".","*","."], ["#","#","#","*",".","."], - ["#","#","#",".","#","."]] - Output: [[".","#","#"], - [".","#","#"], - ["#","#","*"], - ["#","*","."], - ["#",".","*"], - ["#",".","."]] -
-
Constraints:
m == box.length
n == box[i].length
1 <= m, n <= 500
box[i][j]
is either '#'
, '*'
, or '.'
.m == boxGrid.length
n == boxGrid[i].length
1 <= m, n <= 500
boxGrid[i][j]
is either '#'
, '*'
, or '.'
.给定一个整数数组 ribbons
和一个整数 k
,数组每项 ribbons[i]
表示第 i
条绳子的长度。对于每条绳子,你可以将任意切割成一系列长度为正整数的部分,或者选择不进行切割。
给定一个整数数组 ribbons
和一个整数 k
,数组每项 ribbons[i]
表示第 i
条绳子的长度。对于每条绳子,你可以将任意切割成一系列长度为 正整数 的部分,或者选择不进行切割。
例如,如果给你一条长度为 4
的绳子,你可以:
4
不变;3
和一条长度为 1
的绳子;2
的绳子;2
和两条长度为 1
的绳子;1
的绳子。2
的绳子;2
和两条长度为 1
的绳子;1
的绳子。你的任务是最终得到 k
条完全一样的绳子,他们的长度均为相同的正整数。如果绳子切割后有剩余,你可以直接舍弃掉多余的部分。
你的任务是找出最大 x
值,要求满足可以裁切出恰好 k
条长度均为 x
的绳子。你可以丢弃裁切后剩余的任意长度的绳子。如果不可能切割出 k
条相同长度的绳子,返回 0。
对于这 k
根绳子,返回你能得到的绳子最大长度;如果你无法得到 k
根相同长度的绳子,返回 0
。
+
示例 1:
-输入: ribbons = [9,7,5], k = 3 ++输入: ribbons = [9,7,5], k = 3 输出: 5 解释: - 把第一条绳子切成两部分,一条长度为 5,一条长度为 4; @@ -47,7 +46,8 @@ tags:示例 2:
-输入: ribbons = [7,5,9], k = 4 ++输入: ribbons = [7,5,9], k = 4 输出: 4 解释: - 把第一条绳子切成两部分,一条长度为 4,一条长度为 3; @@ -58,12 +58,13 @@ tags:示例 3:
-输入: ribbons = [5,7,9], k = 22 ++输入: ribbons = [5,7,9], k = 22 输出: 0 解释: 由于绳子长度需要为正整数,你无法得到 22 条长度相同的绳子。-+
提示:
diff --git a/solution/1800-1899/1891.Cutting Ribbons/README_EN.md b/solution/1800-1899/1891.Cutting Ribbons/README_EN.md index f7767d80e310b..569ce99a275b7 100644 --- a/solution/1800-1899/1891.Cutting Ribbons/README_EN.md +++ b/solution/1800-1899/1891.Cutting Ribbons/README_EN.md @@ -33,9 +33,7 @@ tags: -Your goal is to obtain
- -k
ribbons of all the same positive integer length. You are allowed to throw away any excess ribbon as a result of cutting.Return the maximum possible positive integer length that you can obtain
+k
ribbons of, or0
if you cannot obtaink
ribbons of the same length.Your task is to determine the maximum length of ribbon,
x
, that allows you to cut exactlyk
ribbons, each of lengthx
. You can discard any leftover ribbon from the cuts. If it is impossible to cutk
ribbons of the same length, return 0.
Example 1:
diff --git a/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/README.md b/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/README.md index 5dc8e5547bfac..e64a42540f4ee 100644 --- a/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/README.md +++ b/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/README.md @@ -115,7 +115,7 @@ tags:
n == positions.length
1 <= n <= 4
pieces
只包含字符串 "rook"
,"queen"
和 "bishop"
。1 <= ri, ci <= 8
positions[i]
互不相同。提示:
1 <= candies.length <= 105
0 <= candies.length <= 105
1 <= candies[i] <= 105
0 <= k <= candies.length
Constraints:
1 <= candies.length <= 105
0 <= candies.length <= 105
1 <= candies[i] <= 105
0 <= k <= candies.length
Allocator(int n)
使用一个大小为 n
的内存数组初始化 Allocator
对象。int allocate(int size, int mID)
找出大小为 size
个连续空闲内存单元且位于 最左侧 的块,分配并赋 id mID
。返回块的第一个下标。如果不存在这样的块,返回 -1
。int free(int mID)
释放 id mID
对应的所有内存单元。返回释放的内存单元数目。int freeMemory(int mID)
释放 id mID
对应的所有内存单元。返回释放的内存单元数目。
示例:
-输入 -["Allocator", "allocate", "allocate", "allocate", "free", "allocate", "allocate", "allocate", "free", "allocate", "free"] ++输入 +["Allocator", "allocate", "allocate", "allocate", "freeMemory", "allocate", "allocate", "allocate", "freeMemory", "allocate", "freeMemory"] [[10], [1, 1], [1, 2], [1, 3], [2], [3, 4], [1, 1], [1, 1], [1], [10, 2], [7]] 输出 [null, 0, 1, 2, 1, 3, 1, 6, 3, -1, 0] 解释 Allocator loc = new Allocator(10); // 初始化一个大小为 10 的内存数组,所有内存单元都是空闲的。 -loc.allocate(1, 1); // 最左侧的块的第一个下标是 0 。内存数组变为 [1, , , , , , , , , ]。返回 0 。 -loc.allocate(1, 2); // 最左侧的块的第一个下标是 1 。内存数组变为 [1,2, , , , , , , , ]。返回 1 。 -loc.allocate(1, 3); // 最左侧的块的第一个下标是 2 。内存数组变为 [1,2,3, , , , , , , ]。返回 2 。 -loc.free(2); // 释放 mID 为 2 的所有内存单元。内存数组变为 [1, ,3, , , , , , , ] 。返回 1 ,因为只有 1 个 mID 为 2 的内存单元。 -loc.allocate(3, 4); // 最左侧的块的第一个下标是 3 。内存数组变为 [1, ,3,4,4,4, , , , ]。返回 3 。 -loc.allocate(1, 1); // 最左侧的块的第一个下标是 1 。内存数组变为 [1,1,3,4,4,4, , , , ]。返回 1 。 -loc.allocate(1, 1); // 最左侧的块的第一个下标是 6 。内存数组变为 [1,1,3,4,4,4,1, , , ]。返回 6 。 -loc.free(1); // 释放 mID 为 1 的所有内存单元。内存数组变为 [ , ,3,4,4,4, , , , ] 。返回 3 ,因为有 3 个 mID 为 1 的内存单元。 +loc.allocate(1, 1); // 最左侧的块的第一个下标是 0 。内存数组变为 [1, , , , , , , , , ]。返回 0 。 +loc.allocate(1, 2); // 最左侧的块的第一个下标是 1 。内存数组变为 [1,2, , , , , , , , ]。返回 1 。 +loc.allocate(1, 3); // 最左侧的块的第一个下标是 2 。内存数组变为 [1,2,3, , , , , , , ]。返回 2 。 +loc.freeMemory(2); // 释放 mID 为 2 的所有内存单元。内存数组变为 [1, ,3, , , , , , , ] 。返回 1 ,因为只有 1 个 mID 为 2 的内存单元。 +loc.allocate(3, 4); // 最左侧的块的第一个下标是 3 。内存数组变为 [1, ,3,4,4,4, , , , ]。返回 3 。 +loc.allocate(1, 1); // 最左侧的块的第一个下标是 1 。内存数组变为 [1,1,3,4,4,4, , , , ]。返回 1 。 +loc.allocate(1, 1); // 最左侧的块的第一个下标是 6 。内存数组变为 [1,1,3,4,4,4,1, , , ]。返回 6 。 +loc.freeMemory(1); // 释放 mID 为 1 的所有内存单元。内存数组变为 [ , ,3,4,4,4, , , , ] 。返回 3 ,因为有 3 个 mID 为 1 的内存单元。 loc.allocate(10, 2); // 无法找出长度为 10 个连续空闲内存单元的空闲块,所有返回 -1 。 -loc.free(7); // 释放 mID 为 7 的所有内存单元。内存数组保持原状,因为不存在 mID 为 7 的内存单元。返回 0 。 +loc.freeMemory(7); // 释放 mID 为 7 的所有内存单元。内存数组保持原状,因为不存在 mID 为 7 的内存单元。返回 0 。diff --git a/solution/2500-2599/2532.Time to Cross a Bridge/README.md b/solution/2500-2599/2532.Time to Cross a Bridge/README.md index 13d8745f06838..bb40a5b144f6f 100644 --- a/solution/2500-2599/2532.Time to Cross a Bridge/README.md +++ b/solution/2500-2599/2532.Time to Cross a Bridge/README.md @@ -20,33 +20,33 @@ tags: -
共有
+k
位工人计划将n
个箱子从旧仓库移动到新仓库。给你两个整数n
和k
,以及一个二维整数数组time
,数组的大小为k x 4
,其中time[i] = [leftToRighti, pickOldi, rightToLefti, putNewi]
。共有
k
位工人计划将n
个箱子从右侧的(旧)仓库移动到左侧的(新)仓库。给你两个整数n
和k
,以及一个二维整数数组time
,数组的大小为k x 4
,其中time[i] = [righti, picki, lefti, puti]
。一条河将两座仓库分隔,只能通过一座桥通行。旧仓库位于河的右岸,新仓库在河的左岸。开始时,所有
k
位工人都在桥的左侧等待。为了移动这些箱子,第i
位工人(下标从 0 开始)可以:
leftToRighti
分钟。pickOldi
分钟。不同工人可以同时搬起所选的箱子。rightToLefti
分钟。putNewi
分钟。不同工人可以同时放下所选的箱子。righti
分钟。picki
分钟。不同工人可以同时搬起所选的箱子。lefti
分钟。puti
分钟。不同工人可以同时放下所选的箱子。如果满足下面任一条件,则认为工人 i
的 效率低于 工人 j
:
leftToRighti + rightToLefti > leftToRightj + rightToLeftj
leftToRighti + rightToLefti == leftToRightj + rightToLeftj
且 i > j
lefti + righti > leftj + rightj
lefti + righti == leftj + rightj
且 i > j
工人通过桥时需要遵循以下规则:
x
到达桥边时,工人 y
正在过桥,那么工人 x
需要在桥边等待。所有 n
个盒子都需要放入新仓库,请你返回最后一个搬运箱子的工人 到达河左岸 的时间。
请你返回最后一个箱子 到达桥左侧 的时间。
@@ -92,7 +92,7 @@ tags:
1 <= n, k <= 104
time.length == k
time[i].length == 4
1 <= leftToRighti, pickOldi, rightToLefti, putNewi <= 1000
1 <= lefti, picki, righti, puti <= 1000
Given an integer array nums
and an integer k
, return the number of good subarrays of nums
.
A subarray arr
is good if it there are at least k
pairs of indices (i, j)
such that i < j
and arr[i] == arr[j]
.
A subarray arr
is good if there are at least k
pairs of indices (i, j)
such that i < j
and arr[i] == arr[j]
.
A subarray is a contiguous non-empty sequence of elements within an array.
diff --git a/solution/2500-2599/2577.Minimum Time to Visit a Cell In a Grid/README_EN.md b/solution/2500-2599/2577.Minimum Time to Visit a Cell In a Grid/README_EN.md index 4da803f6954cf..3c88d6c8193cf 100644 --- a/solution/2500-2599/2577.Minimum Time to Visit a Cell In a Grid/README_EN.md +++ b/solution/2500-2599/2577.Minimum Time to Visit a Cell In a Grid/README_EN.md @@ -72,7 +72,7 @@ The final time is 7. It can be shown that it is the minimum time possible.-