Skip to content

Instantly share code, notes, and snippets.

@lienista
Last active October 11, 2018 22:53
Show Gist options
  • Select an option

  • Save lienista/e6e849d364559c3f19d32a2fe66eec34 to your computer and use it in GitHub Desktop.

Select an option

Save lienista/e6e849d364559c3f19d32a2fe66eec34 to your computer and use it in GitHub Desktop.
Leetcode 2. Add Two Numbers - You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself.
const addTwoLists = (l1, l2) => {
let n1=0, n2=0, count=0;
while(l1 !== null) {
n1 += (l1.val)*Math.pow(10,count);
l1 = l1.next;
count++;
}
count=0;
while(l2 !== null) {
n2 += (l2.val)*Math.pow(10,count);
l2 = l2.next;
count++;
}
return n1+n2;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment