Skip to content

Commit 9c67305

Browse files
committed
fix: docs
1 parent 8d90ebe commit 9c67305

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

solution/0000-0099/0090.Subsets II/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ tags:
5959

6060
### 方法一:排序 + DFS
6161

62-
我们可以先对数组 $nums$ 进行排序,方便去重。
62+
我们可以先对数组 $\textit{nums}$ 进行排序,方便去重。
6363

64-
然后,我们设计一个函数 $dfs(i)$,表示当前从第 $i$ 个元素开始搜索子集。函数 $dfs(i)$ 的执行逻辑如下:
64+
然后,我们设计一个函数 $\textit{dfs}(i)$,表示当前从第 $i$ 个元素开始搜索子集。函数 $\textit{dfs}(i)$ 的执行逻辑如下:
6565

6666
如果 $i \geq n$,说明已经搜索完所有元素,将当前子集加入答案数组中,递归结束。
6767

68-
如果 $i < n$,将第 $i$ 个元素加入子集,执行 $dfs(i + 1)$,然后将第 $i$ 个元素从子集中移除。接下来,我们判断第 $i$ 个元素是否和下一个元素相同,如果相同,则循环跳过该元素,直到找到第一个和第 $i$ 个元素不同的元素,执行 $dfs(i + 1)$。
68+
如果 $i < n$,将第 $i$ 个元素加入子集,执行 $\textit{dfs}(i + 1)$,然后将第 $i$ 个元素从子集中移除。接下来,我们判断第 $i$ 个元素是否和下一个元素相同,如果相同,则循环跳过该元素,直到找到第一个和第 $i$ 个元素不同的元素,执行 $\textit{dfs}(i + 1)$。
6969

70-
最后,我们只需要调用 $dfs(0)$,返回答案数组即可。
70+
最后,我们只需要调用 $\textit{dfs}(0)$,返回答案数组即可。
7171

72-
时间复杂度 $O(n \times 2^n)$,空间复杂度 $O(n)$。其中 $n$ 是数组的长度
72+
时间复杂度 $O(n \times 2^n)$,空间复杂度 $O(n)$。其中 $n$ 是数组 $\textit{nums}$ 的长度
7373

7474
<!-- tabs:start -->
7575

@@ -308,13 +308,13 @@ public class Solution {
308308

309309
### 方法二:排序 + 二进制枚举
310310

311-
与方法一类似,我们先对数组 $nums$ 进行排序,方便去重。
311+
与方法一类似,我们先对数组 $\textit{nums}$ 进行排序,方便去重。
312312

313-
接下来,我们在 $[0, 2^n)$ 的范围内枚举一个二进制数 $mask$,其中 $mask$ 的二进制表示是一个 $n$ 位的位串,如果 $mask$ 的第 $i$ 位为 $1$,表示选择 $nums[i]$,为 $0$ 表示不选择 $nums[i]$。注意,如果 $mask$ 的 $i - 1$ 位为 $0$,且 $nums[i] = nums[i - 1]$,则说明在当前枚举到的方案中,第 $i$ 个元素和第 $i - 1$ 个元素相同,为了避免重复,我们跳过这种情况。否则,我们将 $mask$ 对应的子集加入答案数组中。
313+
接下来,我们在 $[0, 2^n)$ 的范围内枚举一个二进制数 $\textit{mask}$,其中 $\textit{mask}$ 的二进制表示是一个 $n$ 位的位串,如果 $\textit{mask}$ 的第 $i$ 位为 $1$,表示选择 $\textit{nums}[i]$,为 $0$ 表示不选择 $\textit{nums}[i]$。注意,如果 $\textit{mask}$ 的 $i - 1$ 位为 $0$,且 $\textit{nums}[i] = \textit{nums}[i - 1]$,则说明在当前枚举到的方案中,第 $i$ 个元素和第 $i - 1$ 个元素相同,为了避免重复,我们跳过这种情况。否则,我们将 $\textit{mask}$ 对应的子集加入答案数组中。
314314

315315
枚举结束后,我们返回答案数组即可。
316316

317-
时间复杂度 $O(n \times 2^n)$,空间复杂度 $O(n)$。其中 $n$ 是数组的长度
317+
时间复杂度 $O(n \times 2^n)$,空间复杂度 $O(n)$。其中 $n$ 是数组 $\textit{nums}$ 的长度
318318

319319
<!-- tabs:start -->
320320

solution/0000-0099/0090.Subsets II/README_EN.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ tags:
4646

4747
### Solution 1: Sorting + DFS
4848

49-
We can first sort the array $nums$ to facilitate deduplication.
49+
We can first sort the array $\textit{nums}$ to facilitate deduplication.
5050

51-
Then, we design a function $dfs(i)$, which represents searching for subsets starting from the $i$-th element. The execution logic of the function $dfs(i)$ is as follows:
51+
Then, we design a function $\textit{dfs}(i)$, which represents the current search for subsets starting from the $i$-th element. The execution logic of the function $\textit{dfs}(i)$ is as follows:
5252

53-
If $i \geq n$, it means that all elements have been searched, and the current subset is added to the answer array, and the recursion ends.
53+
If $i \geq n$, it means all elements have been searched, add the current subset to the answer array, and end the recursion.
5454

55-
If $i < n$, add the $i$-th element to the subset, execute $dfs(i + 1)$, and then remove the $i$-th element from the subset. Next, we judge whether the $i$-th element is the same as the next element. If it is the same, we loop to skip this element until we find the first element that is different from the $i$-th element, and execute $dfs(i + 1)$.
55+
If $i < n$, add the $i$-th element to the subset, execute $\textit{dfs}(i + 1)$, then remove the $i$-th element from the subset. Next, we check if the $i$-th element is the same as the next element. If they are the same, skip the element in a loop until we find the first element different from the $i$-th element, then execute $\textit{dfs}(i + 1)$.
5656

57-
Finally, we only need to call $dfs(0)$ and return the answer array.
57+
Finally, we only need to call $\textit{dfs}(0)$ and return the answer array.
5858

59-
The time complexity is $O(n \times 2^n)$, and the space complexity is $O(n)$. Here, $n$ is the length of the array.
59+
The time complexity is $O(n \times 2^n)$, and the space complexity is $O(n)$. Here, $n$ is the length of the array $\textit{nums}$.
6060

6161
<!-- tabs:start -->
6262

@@ -295,13 +295,13 @@ public class Solution {
295295

296296
### Solution 2: Sorting + Binary Enumeration
297297

298-
Similar to Solution 1, we first sort the array $nums$ to facilitate deduplication.
298+
Similar to Solution 1, we first sort the array $\textit{nums}$ to facilitate deduplication.
299299

300-
Next, we enumerate a binary number $mask$ in the range of $[0, 2^n)$, where the binary representation of $mask$ is an $n$-bit bit string. If the $i$-th bit of $mask$ is $1$, it means to select $nums[i]$, and $0$ means not to select $nums[i]$. Note that if the $i - 1$ bit of $mask$ is $0$, and $nums[i] = nums[i - 1]$, it means that in the current enumerated scheme, the $i$-th element and the $i - 1$-th element are the same. To avoid repetition, we skip this situation. Otherwise, we add the subset corresponding to $mask$ to the answer array.
300+
Next, we enumerate a binary number $\textit{mask}$ in the range $[0, 2^n)$, where the binary representation of $\textit{mask}$ is an $n$-bit bit string. If the $i$-th bit of $\textit{mask}$ is $1$, it means selecting $\textit{nums}[i]$, and $0$ means not selecting $\textit{nums}[i]$. Note that if the $(i - 1)$-th bit of $\textit{mask}$ is $0$ and $\textit{nums}[i] = \textit{nums}[i - 1]$, it means that the $i$-th element is the same as the $(i - 1)$-th element in the current enumeration scheme. To avoid duplication, we skip this case. Otherwise, we add the subset corresponding to $\textit{mask}$ to the answer array.
301301

302-
After the enumeration ends, we return the answer array.
302+
After the enumeration, we return the answer array.
303303

304-
The time complexity is $O(n \times 2^n)$, and the space complexity is $O(n)$. Here, $n$ is the length of the array.
304+
The time complexity is $O(n \times 2^n)$, and the space complexity is $O(n)$. Here, $n$ is the length of the array $\textit{nums}$.
305305

306306
<!-- tabs:start -->
307307

0 commit comments

Comments
 (0)