public static LeetCode138Node CopyRandomList(LeetCode138Node head) { if (head == null) { return(null); } if (tracker.ContainsKey(head)) { return(tracker[head]); } var newNode = new LeetCode138Node(head.Value, null, null); tracker.Add(head, newNode); newNode.Next = CopyRandomList(head.Next); newNode.Random = CopyRandomList(head.Random); return(newNode); }
public LeetCode138Node(int value, LeetCode138Node next, LeetCode138Node random) { Value = value; Next = next; Random = random; }