You are given two numbers in the form of linked list.Add them without reversing the linked lists. linked lists can be of any length.
Take two stacks and push a linked list to a stack. After done pushing, simply start popping the stacks, add the numbers, get the carry over, generate another node with the result and add to front to a new linked list.
We have already done this question here, which involves reversal of 2 numbers and then adding it. See the post here.
Take two stacks and push a linked list to a stack. After done pushing, simply start popping the stacks, add the numbers, get the carry over, generate another node with the result and add to front to a new linked list.
We have already done this question here, which involves reversal of 2 numbers and then adding it. See the post here.
0 comments:
Post a Comment