According to leetcode this is the definition of a linked list
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
How do you create a single node that when called outputs
[]
instead of
[0]
In the merge two linked lists if we pass two empty nodes then the output is also an empty node, the question is how do you make an empty ListNode that has a value other than 0 or None
I had the same problem as you but I just figured it out. All you have to do is return None and Leetcode will accept it. I tested it on Leetcode problem 23, Merge k Sorted Lists.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With