Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
itcharge committed May 15, 2024
2 parents 2879d5f + 9c66e95 commit de76fbf
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Solutions/0687. 最长同值路径.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
那么现在问题就变成为如何求「子树的高度」和「子树中的最大直径」。

1. 子树的高度:我们可以利用深度优先搜索方法,递归遍历左右子树,并分别返回左右子树的高度。
2. 子树中的最大直径:我们可以在递归求解子树高度的时候维护一个 $ans$ 变量,用于记录所有 $\text{左子树高度} + \text{右子树高度$ 中的最大值。
2. 子树中的最大直径:我们可以在递归求解子树高度的时候维护一个 $ans$ 变量,用于记录所有 $\text{左子树高度} + \text{右子树高度}$ 中的最大值。

最终 $ans$ 就是我们所求的该二叉树的最大直径。

Expand Down
4 changes: 2 additions & 2 deletions Solutions/0719. 找出第 K 小的数对距离.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# [0719. 找出第 k 小的距离对](https://leetcode.cn/problems/find-k-th-smallest-pair-distance/)
# [0719. 找出第 K 小的距离对](https://leetcode.cn/problems/find-k-th-smallest-pair-distance/)

- 标签:数组、双指针、二分查找、排序
- 难度:困难

## 题目链接

- [0719. 找出第 k 小的距离对 - 力扣](https://leetcode.cn/problems/find-k-th-smallest-pair-distance/)
- [0719. 找出第 K 小的距离对 - 力扣](https://leetcode.cn/problems/find-k-th-smallest-pair-distance/)

## 题目大意

Expand Down
2 changes: 1 addition & 1 deletion Solutions/1349. 参加考试的最大学生数.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

因为学生可以看到左侧、右侧、左上方、右上方这四个方向上紧邻他的学生答卷,所以对于当前排的某个座位来说,其左侧、右侧、左上方、右上方都不应有人坐。我们可以根据当前排的座位选取状态 $cur\underline{\hspace{0.5em}}state$,并通过枚举的方式,找出符合要求的上一排座位选取状态 $pre\underline{\hspace{0.5em}}state$,并计算出当前排座位选择个数,即 $f(cur\underline{\hspace{0.5em}}state)$,则状态转移方程为:

$dp[i][state] = \max \lbrace dp[i - 1][pre\underline{\hspace{0.5em}}state]\rbrace + f(state) $
$dp[i][state] = \max \lbrace dp[i - 1][pre\underline{\hspace{0.5em}}state] \rbrace + f(state)$

因为所给座位中还有坏座位(不可用)的情况,我们可以使用一个 $8$ 位的二进制数 $bad\underline{\hspace{0.5em}}seat$ 来表示当前排的坏座位情况,如果 $cur\underline{\hspace{0.5em}}state \text{ \& } bad\underline{\hspace{0.5em}}seat == 1$,则说明当前状态下,选择了坏椅子,则可直接跳过这种状态。

Expand Down
2 changes: 1 addition & 1 deletion Solutions/2156. 查找给定哈希值的子串.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

我们可以把上面的式子转变为:

$\begin{align} Hash(s_{[i - 1, i + k - 2]}) &= \{[Hash(s_{[i, i + k - 1]}) - s_{i + k - 1} \times d^{k - 1}] \times d + s_{i - 1} \times d^{0} \} \mod m \cr &= \{[Hash(s_{[i, i + k - 1]}) - s_{i + k - 1} \times d^{k - 1}] \times d \mod m + s_{i - 1} \times d^{0} \mod m \} \mod m \cr &= \{[Hash(s_{[i, i + k - 1]}) - s_{i + k - 1} \times d^{k - 1}] \mod m \times d \mod m + s_{i - 1} \times d^{0} \mod m \} \mod m \end{align}$
$$\begin{aligned} Hash(s_{[i - 1, i + k - 2]}) &= \{[Hash(s_{[i, i + k - 1]}) - s_{i + k - 1} \times d^{k - 1}] \times d + s_{i - 1} \times d^{0} \} \mod m \cr &= \{[Hash(s_{[i, i + k - 1]}) - s_{i + k - 1} \times d^{k - 1}] \times d \mod m + s_{i - 1} \times d^{0} \mod m \} \mod m \cr &= \{[Hash(s_{[i, i + k - 1]}) - s_{i + k - 1} \times d^{k - 1}] \mod m \times d \mod m + s_{i - 1} \times d^{0} \mod m \} \mod m \end{aligned}$$

> 注意:这里之所以用了「反向迭代」而不是「正向迭代」是因为如果使用了正向迭代,那么每次移除的最左侧字符哈希值为 $val(s[i]) * p^0$,之后整体需要除以 $p$,再移入最右侧字符哈希值为($val(s[i+k]) * p^{k-1})$)。
>
Expand Down

0 comments on commit de76fbf

Please sign in to comment.