Q002 Add Two Numbers
Two pointers to add numbers node by node
Tricks:
1. we need variable carry 4 + 7 = 11, we should make the sum of the current node to be 1, carry 1 to the next node
2. we have to consider one list contains more node than the other one, so the loop goes until nodes in both list and carry are 0
https://github.com/Sylvia-YiyinShen/Algorithm/blob/master/TwoPointers/Q002AddTwoNumbers.playground/Contents.swift
No comments:
Post a Comment