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 23ca9e4

Browse files
committed
添加了684.冗余连接 的Python并查集简洁写法
1 parent a0462c4 commit 23ca9e4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎problems/0684.冗余连接.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,23 @@ class Solution:
256256
return []
257257
```
258258

259+
### Python简洁写法:
260+
261+
```python
262+
class Solution:
263+
def findRedundantConnection(self, edges: List[List[int]]) -> List[int]:
264+
n = len(edges)
265+
p = [i for i in range(n+1)]
266+
def find(i):
267+
if p[i] != i:
268+
p[i] = find(p[i])
269+
return p[i]
270+
for u, v in edges:
271+
if p[find(u)] == find(v):
272+
return [u, v]
273+
p[find(u)] = find(v)
274+
```
275+
259276
### Go
260277

261278
```go

0 commit comments

Comments
(0)

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