def isPalindrome(linkedList): stack = LinkedList() res = True slow = linkedList.head fast = linkedList.head count=0 while(fast!= None and fast.next !=None): count += 1 stack.push(Node(slow.data)) slow = slow.next fast = fast.next.next if(fast != None): slow = slow.next while(slow!= None): val1 = slow.data val2 = stack.pop() if(val1 != val2): res = False break slow = slow.next return res
def addDigits(l1, l2): result, carry = None, 0 if (l1.next or l2.next): result, carry = addDigits(l1.next, l2.next) if (not result): result = LinkedList() sum = l1.data + l2.data + carry print(f"{l1.data} + {l2.data} + {carry} = {sum}") result.push(Node(sum % 10)) carry = sum // 10 return result, carry