[Leetcode] 2. Add Two Numbers QuestionEditorial Solution
public static ListNode AddTwoNumbers(ListNode l1, ListNode l2)
{
ListNode ret = new ListNode(0);
ListNode cur = ret;
int sum = 0;
while (true)
{
if (l1 != null)
{
sum += l1.val;
l1 = l1.next;
}
if (l2 != null)
{
sum += l2.val;
l2 = l2.next;
}
cur.val = sum % 10;
sum /= 10;
if (l1 != null || l2 != null || sum != 0)
{
cur = (cur.next = new ListNode(0));
}
else
break;
}
return ret;
}
相關文章
- LeetCode 2. Add Two NumbersLeetCode
- LeetCode 2 Add Two NumbersLeetCode
- LeetCode-2 Add Two NumbersLeetCode
- LeetCode2: Add two numbers(兩數相加)LeetCode
- Fifth. LeetCode 2:Add Two Numbers 兩數之和LeetCode
- Add_Two_Numbers python 求解Python
- leetcode 兩數相加(add two numbers) Python程式設計實現LeetCodePython程式設計
- 421-Maximum XOR of Two Numbers in an Array
- Solution - Atcoder Atcoder ARC137C Distinct Numbers
- Leetcode 165 Compare Version NumbersLeetCode
- Leetcode 67 Add BinaryLeetCode
- Leetcode 231 Power of TwoLeetCode
- Leetcode 1 two sumLeetCode
- LeetCode | 1 Two SumLeetCode
- Leetcode 967 Numbers With Same Consecutive DifferencesLeetCode
- [LeetCode] 258. Add DigitsLeetCodeGit
- Leetcode 29 Divide Two IntegersLeetCodeIDE
- LeetCode-1 Two SumLeetCode
- [LeetCode]1.Two SumLeetCode
- LeetCode | 349 Intersection Of Two ArraysLeetCode
- Leetcode 231. Power of TwoLeetCode
- python: leetcode - 1 Two SumPythonLeetCode
- LeetCode 129. Sum Root to Leaf NumbersLeetCode
- [LeetCode] 282. Expression Add OperatorsLeetCodeExpress
- leetcode-29. Divide Two IntegersLeetCodeIDE
- Leetcode 21 Merge Two Sorted ListsLeetCode
- LeetCode: Two sum(兩數之和)LeetCode
- [LeetCode] 29. Divide Two IntegersLeetCodeIDE
- Leetcode 4 Median of Two Sorted ArraysLeetCode
- 【Leetcode】1029. Two City SchedulingLeetCode
- leetcode 371. Sum of Two IntegersLeetCode
- LeetCode之Sum of Even Numbers After Queries(Kotlin)LeetCodeKotlin
- LeetCode 448. Find All Numbers Disappeared in an ArrayLeetCodeAPP
- leetcode 2. 兩數相加LeetCode
- LeetCode 2.兩數相加LeetCode
- LeetCode 21. Merge Two Sorted ListsLeetCode
- LeetCode 4. Median of Two Sorted ArraysLeetCode
- LeetCode #1:Two Sum(簡單題)LeetCode
- LeetCode Two Sum(001)解法總結LeetCode