May-18-2022, 02:38 PM
(May-18-2022, 02:31 PM)walter Wrote: Hi guys,
i am a newbie in Python. I have a problem with an OOP issue. This is my code
class Solution:
def __init__(self):
self.head = None
def addTwoNumbers(self, lista1, lista2):
carry = 0
Current1 = lista1.head
Current2 = lista2.head
ResultCurrent = self.head
while (Current1.next != None and Current2.next != None ):
if (Current1.data)+(Current2.data) > 10:
datanew = Current1.data + Current2.data - 10 + carry
carry = 1
ResultCurrent.insert(datanew)
else:
datanew = Current1.data + Current2.data + carry
ResultCurrent.insert(datanew)
carry = 0
Current1 = Current1.next
Current2 = Current2.next
ResultCurrent = ResultCurrent.next
Follow the main:
def main():
LL1 = LinkedList()
LL1.insert(3)
LL1.insert(4)
LL1.insert(5)
LL1.printLL()
LL2 = LinkedList()
LL2.insert(6)
LL2.insert(7)
LL2.insert(8)
LL2.printLL()
result = Solution()
result.addTwoNumbers(self, LL1, LL2)
result.printListLinked()
When i try to run this code i have an errore regarding the first argument of method of Solution class addTwoNumbers.
Thanks to community for your help.
Walter