Skip to content

Commit ea777fb

Browse files
committed
refactor
1 parent 6bc50e5 commit ea777fb

File tree

1 file changed

+4
-10
lines changed
  • Minimum Spanning Tree/MinimumSpanningTree.playground/Sources

1 file changed

+4
-10
lines changed

Minimum Spanning Tree/MinimumSpanningTree.playground/Sources/Graph.swift

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,11 @@ public struct Graph<T: Hashable>: CustomStringConvertible {
3737
vertices.insert(v1)
3838
vertices.insert(v2)
3939

40-
if let _ = adjList[v1] {
41-
adjList[v1]?.append((vertex: v2, weight: w))
42-
} else {
43-
adjList[v1] = [(vertex: v2, weight: w)]
44-
}
40+
adjList[v1] = adjList[v1] ?? []
41+
adjList[v1]?.append((vertex: v2, weight: w))
4542

46-
if let _ = adjList[v2] {
47-
adjList[v2]?.append((vertex: v1, weight: w))
48-
} else {
49-
adjList[v2] = [(vertex: v1, weight: w)]
50-
}
43+
adjList[v2] = adjList[v2] ?? []
44+
adjList[v2]?.append((vertex: v1, weight: w))
5145
}
5246

5347
public mutating func addEdge(_ edge: Edge<T>) {

0 commit comments

Comments
 (0)