Cloned undirected graph
This commit is contained in:
@@ -147,3 +147,23 @@ class Node:
|
||||
ret += self.left.__list__() if self.left is not None else [None]
|
||||
ret += self.next.__list__() if self.next is not None else [None]
|
||||
return ret
|
||||
|
||||
|
||||
class NeighborlyNode:
|
||||
"""NeighborlyNode is a "Node" type used in leetcode graph puzzles"""
|
||||
|
||||
def __init__(self, val=0, neighbors=None):
|
||||
self.val = val
|
||||
self.neighbors = neighbors if neighbors is not None else []
|
||||
|
||||
|
||||
class NeighborlyNodeNicely(typing.NamedTuple):
|
||||
val: int
|
||||
neighbors: list["NeighborlyNodeNicely"]
|
||||
|
||||
def __eq__(self, other: typing.Optional["NeighborlyNodeNicely"]) -> bool:
|
||||
return (
|
||||
other is not None
|
||||
and self.val == other.val
|
||||
and [n.val for n in self.neighbors] == [n.val for n in other.neighbors]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user