You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[//]: #(<p>Given the head node of a linked list <code>head</code> ,The first node returning to the linked list to start the ring。 <em>If the linked linked linked,Then return <code>null</code>。</em></p>)
14
-
15
-
[//]: #()
16
-
[//]: #(<p>If there is a node in the linked list,Can be tracked continuously <code>next</code> The pointer arrives again,Then there is a ring in the linked list。 To show the ring in the linked list,Internal use of the evaluation system <code>pos</code> Let's represent the position connected to the linked list to the position of the linked list(<strong>Index 0 start</strong>)。if <code>pos</code> yes <code>-1</code>,There is no ring in this linked list。<strong>Notice:<code>pos</code> Pass the non -as a parameter</strong>,仅仅yes为了标识Linked的实际情况。</p>)
17
-
18
-
[//]: #()
19
-
[//]: #(<p><strong>Modification is not allowed </strong>Linked。</p>)
20
-
21
-
[//]: #()
22
-
[//]: #(<ul> )
23
-
24
-
[//]: #(</ul>)
25
-
26
-
[//]: #()
27
-
[//]: #(<p> </p>)
28
-
29
-
[//]: #()
30
-
[//]: #(<p><strong>Exemplary example 1:</strong></p>)
[//]: #( <li><code>pos</code> Value <code>-1</code> 或者Linked中的一indivualhave效索引</li> )
94
-
95
-
[//]: #(</ul>)
11
+
[//]: #
12
+
[//]: #"# topic:"
13
+
[//]: #"<p>Given the head node of a linked list <code>head</code> ,The first node returning to the linked list to start the ring。 <em>If the linked linked linked,Then return <code>null</code>。</em></p>"
14
+
[//]: #
15
+
[//]: #"<p>If there is a node in the linked list,Can be tracked continuously <code>next</code> The pointer arrives again,Then there is a ring in the linked list。 To show the ring in the linked list,Internal use of the evaluation system <code>pos</code> Let's represent the position connected to the linked list to the position of the linked list(<strong>Index 0 start</strong>)。if <code>pos</code> yes <code>-1</code>,There is no ring in this linked list。<strong>Notice:<code>pos</code> Pass the non -as a parameter</strong>,仅仅yes为了标识Linked的实际情况。</p>"
16
+
[//]: #
17
+
[//]: #"<p><strong>Modification is not allowed </strong>Linked。</p>"
18
+
[//]: #
19
+
[//]: #"<ul> "
20
+
[//]: #"</ul>"
21
+
[//]: #
22
+
[//]: #"<p> </p>"
23
+
[//]: #
24
+
[//]: #"<p><strong>Exemplary example 1:</strong></p>"
这类Linkedtopic一般都yes使用双pointer法解决的,For example, looking for distance tail K Node、Find a ring entrance、Find the entrance of the public tail, etc.。
71
+
102
72
### Algorithm:
73
+
103
74
1. Double pointer met for the first time: Set two pointers fast,slow 指向Linked头部 head,fast Walk per round 2 step,slow Walk per round 1 step;
104
75
105
-
a. First result: fast pointer走过Linked末端,说明Linked无环,直接return null;
76
+
a. First result: fast pointer走过Linked末端,说明Linked无环,直接return null;
106
77
107
-
.TIPS: If there is a ring,Two pointers will definitely meet。Because every time I go 1 wheel,fast and slow Pitch +1,fast The event will catch up slow;
108
-
b. Second result: whenfast == slowhour, Two pointers in the ring First encounter 。下面分析此hourfast and slowPassing step数关系 :
78
+
.TIPS: If there is a ring,Two pointers will definitely meet。Because every time I go 1 wheel,fast and slow Pitch +1,fast The event will catch up slow;
79
+
b. Second result: whenfast == slowhour, Two pointers in the ring First encounter 。下面分析此hourfast and slowPassing step数关系 :
109
80
110
-
.设Linked共have a+b Node,in Linked头部到Linked入口 have a Node(不计Linked入口节点), Linked环 have b Node(这里需要Notice,a and b yes未知数,例如图解上Linked a=4 , b=5);Set two pointers分别走了 f,s step,则have:
111
-
a. fast 走的step数yesslowstep数的 2 Double,Right now f=2s;(Analyze: fast Walk per round 2 step)
112
-
b.fast Compare slowGo more n Length of a ring,Right now f=s+nb;( Analyze: Double pointers have gone through a step,然后在环Inside绕圈直到重合,重合hour fast Compare slow Go 环的长度整数Double );
113
-
.The above two types are reduced:f=2nb,s=nb,Right nowfastandslow The pointer left separately 2n,n indivual Circumference of the ring (Notice: n yes未知数,不同Linked的情况不同)。
81
+
.设Linked共have a+b Node,in Linked头部到Linked入口 have a Node(不计Linked入口节点), Linked环 have b Node(这里需要Notice,a and b yes未知数,例如图解上Linked a=4 , b=5);Set two pointers分别走了 f,s step,则have:
82
+
a. fast 走的step数yesslowstep数的 2 Double,Right now f=2s;(Analyze: fast Walk per round 2 step)
83
+
b.fast Compare slowGo more n Length of a ring,Right now f=s+nb;( Analyze: Double pointers have gone through a step,然后在环Inside绕圈直到重合,重合hour fast Compare slow Go 环的长度整数Double );
84
+
.The above two types are reduced:f=2nb,s=nb,Right nowfastandslow The pointer left separately 2n,n indivual Circumference of the ring (Notice: n yes未知数,不同Linked的情况不同)。
114
85
115
86
<!--more-->
116
87
117
88
2. Current situation analysis:
118
89
119
-
.if让pointer从Linked头部一直向前走并统计step数k,那么所have 走到Linked入口节点hour的step数 yes:k=a+nb(Leave first a step到入口节点,Over time 1 Ring( b step)I will go to the entrance node again)。
120
-
121
-
..Current,slow pointerPassingstep数为 nb step。therefore,We just find a way slow Go again a step停下来,You can get to the entrance to the ring。
122
-
90
+
.if让pointer从Linked头部一直向前走并统计step数k,那么所have 走到Linked入口节点hour的step数 yes:k=a+nb(Leave first a step到入口节点,Over time 1 Ring( b step)I will go to the entrance node again)。
91
+
92
+
..Current,slow pointerPassingstep数为 nb step。therefore,We just find a way slow Go again a step停下来,You can get to the entrance to the ring。
93
+
123
94
...但yes我们不知道 a Value,what to do?依然yes使用双pointer法。我们构建一indivualpointer,此pointer需要have以下性质:此pointerandslow Go forward together a step后,The two nodes at the entrance re -coincide。So where does it need to get to the entrance node? a step?答案yesLinked头部head。
124
95
125
96
3. Double pointer met for the second time:
126
-
.slowpointer Unchanged position ,Willfastpointer重新 指向Linked头部节点 ;slowandfast同hour每wheel向前走 1 step;
97
+
.slowpointer Unchanged position ,Willfastpointer重新 指向Linked头部节点 ;slowandfast同hour每wheel向前走 1 step;
127
98
128
-
..TIPS:此hour f=0,s=nb ;
129
-
...when fast pointer走到f=a stephour,slow pointer走到steps=a+nb,此hour 两pointer重合,并同hour指向Linked环入口 。
99
+
..TIPS:此hour f=0,s=nb ;
100
+
...when fast pointer走到f=a stephour,slow pointer走到steps=a+nb,此hour 两pointer重合,并同hour指向Linked环入口 。
130
101
131
102
4. returnslowpointer指向的节点。
132
103
133
104
### Complexity analysis:
105
+
134
106
hour间复杂度 O(N) :In the second encounter,慢pointer须走step数 a<a+b;First encounter中,慢pointer须走step数 a+b−x<a+b,in x 为双pointer重合点and环入口距离;therefore总体为线性复杂度;
Copy file name to clipboardExpand all lines: app/docs/CommunityShare/Leetcode/6323. 将钱分给最多的儿童_translated.md
+10-4Lines changed: 10 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,15 @@
1
1
---
2
2
title: 6323. Child that divides money the most.md
3
-
date: '2024.01.01 0:00'
3
+
date: "2024.01.01 0:00"
4
4
tags:
5
5
- - Python
6
6
- - answer
7
7
abbrlink: b9130c0e
8
+
docId: kw44if3s2zi4w2gs1gfhxvoz
8
9
---
9
10
10
11
# topic:
12
+
11
13
I met for the first time:'2023/3/19-16:51'
12
14
13
15
[6323. Child that divides money the most.md](https://leetcode.cn/problems/distribute-money-to-maximum-children/)
@@ -38,8 +40,10 @@ if money>8×children,So children−1 A child obtained 8 Dollar,剩下的一A
38
40
if money=8×children−4,So children−2 A child obtained 8 Dollar,The remaining two children sharing the rest 12 Dollar(As long as not 4, 8 Dollar就行),return children−2。
39
41
40
42
if,We assumed that there are x A child obtained 8 Dollar,Then the rest of the money is money−8×x,As long as it is guaranteed to be greater than equal to the remaining number of children children−x,You can satisfy the meaning。therefore,We just need to ask x Maximum value,That is the answer。
Copy file name to clipboardExpand all lines: app/docs/CommunityShare/Leetcode/994.腐烂的橘子_translated.md
+11-7Lines changed: 11 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,18 @@
1
1
---
2
2
title: 994.Rotten orange.md
3
-
date: 2024.05.14 0:00
3
+
date: "2024.05.14 0:00"
4
4
tags:
5
5
- Python
6
6
- BFS
7
7
- Bilateral queue
8
8
abbrlink: 56e64fdd
9
+
docId: axhoyzdtxoc82q58j1os57c8
9
10
---
10
11
11
12
# topic:
12
13
13
14
"""
15
+
14
16
<p>Given <code>m x n</code> grid
15
17
<metacharset="UTF-8" /> <code>grid</code> middle,Each cell can have one of the following three values:</p>
16
18
@@ -68,6 +70,7 @@ abbrlink: 56e64fdd
68
70
# Thought:
69
71
70
72
这个问题可以用Priority search(BFS)To solve。We need to track the spread of rotten oranges,Record time,And check if there is a fresh orange that cannot be rotten。The initial idea of the original idea:
0 commit comments