Add Two Numbers 2

原创 2016年08月29日 22:36:21

You are given two linked lists representing two non-negative numbers. 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.

两个链表,反向存储,

2->4->3    代表342

5->6->4   代表46

相加为    807   7 -> 0 -> 8

注意进位是反向进位,


超大数相加

见到的方法

1)多项式  a1*x^n + a2*x^(n-1) ....ak*x^(k) ....am*x^0


2)链表    两个链表可能不是一样道长度,多余的长度链表直接 拷过去

逆向存储,不用考虑位对齐,首位是个位。。。

特征




2. Add Two Numbers官方通过版本(8.46%)

public class AddTwoNumbers { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { Lis...
  • ithouse
  • ithouse
  • 2016年01月05日 15:58
  • 210

leetcode——2——Add Two Numbers

You are given two linked lists representing two non-negative numbers. The digits are stored in rever...

LeetCode-2. Add Two Numbers

You are given two linked lists representing two non-negative numbers. The digits are stored in rever...

LeetCode - 2. Add Two Numbers

一开始的想法是先把两个数都从Linked List中解析出来,相加然后再将其转化为Linked List,但是这种解法非常麻烦,而且这三步完全可以同时进行。 首先设置一个dummyNode作为sum...

Leetcode: Add Two Numbers (2)

You are given two linked lists representing two non-negative numbers. The digits are stored in orde...
  • lzmaths
  • lzmaths
  • 2013年12月18日 14:19
  • 406

LeetCode Algorithms 2. Add Two Numbers 题解

题目: You are given two non-empty linked lists representing two non-negative integers. The digits...

LeetCode#2 Add Two Numbers

题目:You are given two non-empty linked lists representing two non-negative integers. The digits are s...

leetcode 2. Add Two Numbers

1.题目描述                                                                                              ...

算法设计Week1 LeetCode Algorithms Problem #2 Add Two Numbers

题目描述 You are given two non-empty linked lists representing two non-negative integers. The digits...

leetCode 2 Add Two Numbers

问题:Add Two Numbers You are given two linked lists representing two non-negative numbers. The digits...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Add Two Numbers 2
举报原因:
原因补充:

(最多只允许输入30个字)