The most retarded solution of all time - Python


  • 0
    J
    class Solution(object):
        def addTwoNumbers(self, l1, l2):
    
            answer = []
            carry = 0
            while l1 or l2 or carry==1:
                ans = 0
                try:
                    ans = ans+ l1.val
                except:
                    pass
                try:
                    ans = ans + l2.val
                except:
                    pass
                ans = ans + carry
                carry = 0
                if ans>=10:
                    ans = ans-10
                    answer.append(ans)
                    carry =1
                else:
                    answer.append(ans)
                    carry = 0
                try:
                    l1=l1.next
                except:
                    try:
                        l2=l2.next
                        ans2 = l2.val+carry
                        if ans2>=10:
                            answer.append(ans2-10)
                            carry = 1
                        else:
                            answer.append(ans2)
                            carry = 0
                            
                    except:
                        pass
                    
                try:
                    l2=l2.next
                except:
                    pass
                    
            return answer
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.