Weird copying linked list-ish thing with random
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import dataclasses
|
||||
import typing
|
||||
|
||||
|
||||
@@ -14,6 +15,30 @@ class ListNode:
|
||||
self.next = next
|
||||
|
||||
|
||||
class ListNodeRandom:
|
||||
"""ListNodeRandom is another weirdo linked list thing from
|
||||
leetcode that is obviously very different than a binary tree
|
||||
node :upside_down_face:
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
x: int,
|
||||
next: typing.Optional["ListNodeRandom"] = None,
|
||||
random: typing.Optional["ListNodeRandom"] = None,
|
||||
):
|
||||
self.val = x
|
||||
self.next = next
|
||||
self.random = random
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class ListNodeRandomNicely:
|
||||
val: int
|
||||
next: typing.Optional["ListNodeRandomNicely"] = None
|
||||
random: typing.Optional["ListNodeRandomNicely"] = None
|
||||
|
||||
|
||||
class BinaryTreeNode(typing.Protocol):
|
||||
val: int
|
||||
left: typing.Optional["BinaryTreeNode"]
|
||||
|
||||
Reference in New Issue
Block a user