2021年3月11日星期四

Recursively Combining a node from two linked list into one node to build a new linked list

I'm having issues trying to write a function that takes in two linked lists, takes each node from both, combines them into a tuple, and builds a new linked list.

should print something like this: (1, 2) -> (3, 4) -> (5, 6)

here's what I have and I'm getting errors whenever I run it

def pair(head_one, head_two):  if head_one is not None or head_two is not None:      head = ListNode((head_one.val, head_two.val))      head.next = pair(head_one.next.val, head_two.next.val)      return head  else:      return None  
https://stackoverflow.com/questions/66586757/recursively-combining-a-node-from-two-linked-list-into-one-node-to-build-a-new-l March 12, 2021 at 12:41AM

没有评论:

发表评论