class Solution(object):
def __init__(self, val=0, next=None):
self.val = val
self.next = next
list1 = [1,2,3]
list2 = [1,4,6]
def mergeTwoLists(self, list1, list2):
if not list1:
return list2
if not list2:
return list1
if list1.val < list2.val:
list1.next = self.mergeTwoLists(list1.next, list2)
return list1
else:
list2.next = self.mergeTwoLists(list1, list2.next)
return list2
mergeTwoLists(self, list1, list2)
Have this code above. I thought i initialized the 'self' variable in my init function... but when I try to run this program I am receiving the following error:
name 'self' is not defined
Am I missing something here? Thanks in advance.