Last active
October 11, 2018 22:53
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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