Skip to content

Commit bd64cee

Browse files
longsizhuogithub-actions[bot]
authored andcommitted
chore(docs): sync doc metadata [skip ci]
1 parent 3426382 commit bd64cee

File tree

5 files changed

+175
-126
lines changed

5 files changed

+175
-126
lines changed
Lines changed: 75 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,111 @@
11
---
22
title: 142.Ring linkedII.md
3-
date: '2024.01.01 0:00'
3+
date: "2024.01.01 0:00"
44
tags:
55
- - Python
66
- - answer
77
abbrlink: e2c9cca9
8+
docId: ylpucy1rbbnfpe3t62u8kcfq
89
---
910

10-
[//]: # ()
11-
[//]: # (# topic:)
12-
13-
[//]: # (<p>Given the head node of a linked list &nbsp;<code>head</code>&nbsp;,The first node returning to the linked list to start the ring。&nbsp;<em>If the linked linked linked,Then return&nbsp;<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>&nbsp;</p>)
28-
29-
[//]: # ()
30-
[//]: # (<p><strong>Exemplary example 1:</strong></p>)
31-
32-
[//]: # ()
33-
[//]: # (<p><img src="https://assets.leetcode.com/uploads/2018/12/07/circularlinkedlist.png" /></p>)
34-
35-
[//]: # ()
36-
[//]: # (<pre>)
37-
38-
[//]: # (<strong>enter:</strong>head = [3,2,0,-4], pos = 1)
39-
40-
[//]: # (<strong>Output:</strong>Back indexes 1 的Linked节点)
41-
42-
[//]: # (<strong>explain:</strong>Linked中have一indivual环,The tail is connected to the second node。)
43-
44-
[//]: # (</pre>)
45-
46-
[//]: # ()
47-
[//]: # (<p><strong>Exemplary example&nbsp;2:</strong></p>)
48-
49-
[//]: # ()
50-
[//]: # (<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2018/12/07/circularlinkedlist_test2.png" /></p>)
51-
52-
[//]: # ()
53-
[//]: # (<pre>)
54-
55-
[//]: # (<strong>enter:</strong>head = [1,2], pos = 0)
56-
57-
[//]: # (<strong>Output:</strong>Back indexes 0 的Linked节点)
58-
59-
[//]: # (<strong>explain:</strong>Linked中have一indivual环,The tail is connected to the first node。)
60-
61-
[//]: # (</pre>)
62-
63-
[//]: # ()
64-
[//]: # (<p><strong>Exemplary example 3:</strong></p>)
65-
66-
[//]: # ()
67-
[//]: # (<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2018/12/07/circularlinkedlist_test3.png" /></p>)
68-
69-
[//]: # ()
70-
[//]: # (<pre>)
71-
72-
[//]: # (<strong>enter:</strong>head = [1], pos = -1)
73-
74-
[//]: # (<strong>Output:</strong>return null)
75-
76-
[//]: # (<strong>explain:</strong>Linked中没have环。)
77-
78-
[//]: # (</pre>)
79-
80-
[//]: # ()
81-
[//]: # (<p>&nbsp;</p>)
82-
83-
[//]: # ()
84-
[//]: # (<p><strong>hint:</strong></p>)
85-
86-
[//]: # ()
87-
[//]: # (<ul> )
88-
89-
[//]: # ( <li>Linked中节点的数目范围在范围 <code>[0, 10<sup>4</sup>]</code> Inside</li> )
90-
91-
[//]: # ( <li><code>-10<sup>5</sup> &lt;= Node.val &lt;= 10<sup>5</sup></code></li> )
92-
93-
[//]: # ( <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>"
25+
[//]: #
26+
[//]: # '<p><img src="https://assets.leetcode.com/uploads/2018/12/07/circularlinkedlist.png" /></p>'
27+
[//]: #
28+
[//]: # "<pre>"
29+
[//]: # "<strong>enter:</strong>head = [3,2,0,-4], pos = 1"
30+
[//]: # "<strong>Output:</strong>Back indexes 1 的Linked节点"
31+
[//]: # "<strong>explain:</strong>Linked中have一indivual环,The tail is connected to the second node。"
32+
[//]: # "</pre>"
33+
[//]: #
34+
[//]: # "<p><strong>Exemplary example 2:</strong></p>"
35+
[//]: #
36+
[//]: # '<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2018/12/07/circularlinkedlist_test2.png" /></p>'
37+
[//]: #
38+
[//]: # "<pre>"
39+
[//]: # "<strong>enter:</strong>head = [1,2], pos = 0"
40+
[//]: # "<strong>Output:</strong>Back indexes 0 的Linked节点"
41+
[//]: # "<strong>explain:</strong>Linked中have一indivual环,The tail is connected to the first node。"
42+
[//]: # "</pre>"
43+
[//]: #
44+
[//]: # "<p><strong>Exemplary example 3:</strong></p>"
45+
[//]: #
46+
[//]: # '<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2018/12/07/circularlinkedlist_test3.png" /></p>'
47+
[//]: #
48+
[//]: # "<pre>"
49+
[//]: # "<strong>enter:</strong>head = [1], pos = -1"
50+
[//]: # "<strong>Output:</strong>return null"
51+
[//]: # "<strong>explain:</strong>Linked中没have环。"
52+
[//]: # "</pre>"
53+
[//]: #
54+
[//]: # "<p> </p>"
55+
[//]: #
56+
[//]: # "<p><strong>hint:</strong></p>"
57+
[//]: #
58+
[//]: # "<ul> "
59+
[//]: # " <li>Linked中节点的数目范围在范围 <code>[0, 10<sup>4</sup>]</code> Inside</li> "
60+
[//]: # " <li><code>-10<sup>5</sup> <= Node.val <= 10<sup>5</sup></code></li> "
61+
[//]: # " <li><code>pos</code> Value <code>-1</code> 或者Linked中的一indivualhave效索引</li> "
62+
[//]: # "</ul>"
9663

9764
[142.Ring listII.md](https://leetcode.cn/problems/linked-list-cycle-ii/)
9865

9966
# Thought:
67+
10068
### Problem -solving:
69+
10170
这类Linkedtopic一般都yes使用双pointer法解决的,For example, looking for distance tail K Node、Find a ring entrance、Find the entrance of the public tail, etc.。
71+
10272
### Algorithm:
73+
10374
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;
10475

105-
a. First result: fast pointer走过Linked末端,说明Linked无环,直接return null;
76+
a. First result: fast pointer走过Linked末端,说明Linked无环,直接return null;
10677

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数关系 :
10980

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的情况不同)。
11485

11586
<!--more-->
11687

11788
2. Current situation analysis:
11889

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+
12394
...但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。
12495

12596
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;
12798

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环入口 。
130101

131102
4. returnslowpointer指向的节点。
132103

133104
### Complexity analysis:
105+
134106
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总体为线性复杂度;
135107
Spatial complexity O(1) :双pointer使用常数大小的额外空间。
136108

137-
138-
139-
140109
# Code:
141110

142111
```python
@@ -156,6 +125,7 @@ class Solution:
156125
a, b = a.next, b.next
157126
return b
158127
```
128+
159129
```cpp
160130
class Solution {
161131
public:
@@ -183,4 +153,4 @@ public:
183153
return a;
184154
}
185155
};
186-
```
156+
```

app/docs/CommunityShare/Leetcode/6323. 将钱分给最多的儿童_translated.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
---
22
title: 6323. Child that divides money the most.md
3-
date: '2024.01.01 0:00'
3+
date: "2024.01.01 0:00"
44
tags:
55
- - Python
66
- - answer
77
abbrlink: b9130c0e
8+
docId: kw44if3s2zi4w2gs1gfhxvoz
89
---
910

1011
# topic:
12+
1113
I met for the first time:'2023/3/19-16:51'
1214

1315
[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
3840
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。
3941

4042
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。
43+
4144
# Code:
42-
```python List
45+
46+
```python List
4347
class Solution:
4448
def distMoney(self, money: int, children: int) -> int:
4549
money -= children
@@ -58,7 +62,8 @@ class Solution:
5862
counts -= 1
5963
return counts
6064
```
61-
```python math
65+
66+
```python math
6267
class Solution:
6368
def distMoney(self, money: int, children: int) -> int:
6469
money -= children # 每people至少 1 Dollar
@@ -73,6 +78,7 @@ class Solution:
7378
ans -= 1
7479
return ans
7580
```
81+
7682
```python ylb
7783
class Solution:
7884
def distMoney(self, money: int, children: int) -> int:
@@ -83,4 +89,4 @@ class Solution:
8389
if money == 8 * children - 4:
8490
return children - 2
8591
return (money-children) // 7
86-
```
92+
```

app/docs/CommunityShare/Leetcode/994.腐烂的橘子_translated.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
---
22
title: 994.Rotten orange.md
3-
date: 2024.05.14 0:00
3+
date: "2024.05.14 0:00"
44
tags:
55
- Python
66
- BFS
77
- Bilateral queue
88
abbrlink: 56e64fdd
9+
docId: axhoyzdtxoc82q58j1os57c8
910
---
1011

1112
# topic:
1213

1314
"""
15+
1416
<p>Given&nbsp;<code>m x n</code>&nbsp;grid
1517
<meta charset="UTF-8" />&nbsp;<code>grid</code>&nbsp;middle,Each cell can have one of the following three values:</p>
1618

@@ -68,6 +70,7 @@ abbrlink: 56e64fdd
6870
# Thought:
6971

7072
这个问题可以用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:
73+
7174
```python
7275
class Solution:
7376
def orangesRotting(self, grid: List[List[int]]) -> int:
@@ -79,6 +82,7 @@ class Solution:
7982
# 存入初始队List
8083
bad_orange.append((i, j))
8184
```
85+
8286
Similar to multi -threaded,每个线程存入一个初始队List,初始队List通过BFSGradual diffusion
8387

8488
# Code:
@@ -91,22 +95,22 @@ class Solution:
9195
bad_orange = deque()
9296
fresh_oranges = 0
9397
rows, cols = len(grid), len(grid[0])
94-
98+
9599
# 找到所有初始Rotten orange,And calculate the number of fresh oranges
96100
for i in range(rows):
97101
for j in range(cols):
98102
if grid[i][j] == 2:
99103
bad_orange.append((i, j))
100104
elif grid[i][j] == 1:
101105
fresh_oranges += 1
102-
106+
103107
# 方向Array:up down left right
104108
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
105-
109+
106110
# If there is no fresh orange,直接return 0
107111
if fresh_oranges == 0:
108112
return 0
109-
113+
110114
# BFS
111115
minutes = 0
112116
while bad_orange:
@@ -119,7 +123,7 @@ class Solution:
119123
grid[nx][ny] = 2
120124
fresh_oranges -= 1
121125
bad_orange.append((nx, ny))
122-
126+
123127
# If there are fresh oranges,return -1
124128
return minutes - 1 if fresh_oranges == 0 else -1
125129
```
@@ -184,4 +188,4 @@ func orangesRotting(grid [][]int) int {
184188
}
185189
return minutes - 1
186190
}
187-
```
191+
```

app/docs/CommunityShare/Leetcode/[2490]回环句_translated.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
---
22
title: 2490Return ring sentence
3-
date: '2024.01.01 0:00'
3+
date: "2024.01.01 0:00"
44
tags:
55
- - Python
66
- - answer
77
- - String
88
abbrlink: 5c07686c
9+
docId: pe6o8l76945uo7aqv79ddhii
910
---
1011

1112
# topic:
@@ -28,4 +29,4 @@ class Solution:
2829
if sentence[i][-1] != sentence[i+1][0]:
2930
return False
3031
return True
31-
```
32+
```

0 commit comments

Comments
 (0)