Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 37e45ed

Browse files
✨update: Modify 954
1 parent 98e2823 commit 37e45ed

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

‎LeetCode/951-960/954. 二倍数对数组(中等).md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class Solution {
127127
* $x$ 为奇数,由于 $\frac{x}{2}$ 不为整数,因此 $x$ 只能作为数对中绝对值较小的那个(即 $x$ 入度为 0ドル$),加入队列;
128128
* $x$ 为偶数,首先令 $x$ 的入度 $in[x] = cnts[\frac{x}{2}],ドル代表有 $cnts[\frac{x}{2}]$ 个 $\frac{x}{2}$ 与其对应。当 $in[x] = 0$ 时,说明没有 $\frac{x}{2}$ 与其成对,此时 $x$ 只能作为数对中绝对值较小的那个(即 $x$ 入度为 0ドル$),加入队列。
129129

130-
跑一遍拓扑排序,假设当前出队值为 $t,ドル此时需要消耗掉 $cnts[t]$ 个 $t * 2$ 与其形成数对(即 $cnts[t * 2] -= cnts[t]$ ),同时 $t * 2$ 的入度也要更新(即可 $in[t * 2] -= cnts[t]$ ),若 $in[t * 2] = 0$ 且此时 $cnts[t * 2] > 0,ドル将 $t * 2$ 进行入队。同时由于我们明确减少了 $t * 2$ 的数量,因此需要同步更新 $t * 4$ 的入度,同理,当 $t * 4$ 的入度 $in[t * 4] = 0,ドル同时 $cnts[t * 4] > 0$ 时,需要将 $t * 4$ 进行入队。
130+
跑一遍拓扑排序,假设当前出队值为 $t,ドル此时需要消耗掉 $cnts[t]$ 个 $t * 2$ 与其形成数对(即 $cnts[t * 2] -= cnts[t]$ ),同时 $t * 2$ 的入度也要更新( $in[t * 2] -= cnts[t]$ ),若 $in[t * 2] = 0$ 且此时 $cnts[t * 2] > 0,ドル将 $t * 2$ 进行入队。同时由于我们明确减少了 $t * 2$ 的数量,因此需要同步更新 $t * 4$ 的入度,同理,当 $t * 4$ 的入度 $in[t * 4] = 0,ドル同时 $cnts[t * 4] > 0$ 时,需要将 $t * 4$ 进行入队。
131131

132132

133133
代码:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /