我写了两个版本供参考:
递归版本
ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) {
return addTwoNumbers(l1, l2, 0);
}
ListNode *addTwoNumbers(ListNode *l1, ListNode *l2, int carry) {
...
分类:
其他好文 时间:
2014-09-14 12:53:17
阅读次数:
216
题目:
The gray code is a binary numeral system where two successive values differ in only one bit.
Given a non-negative integer n representing the total number of bits in the code, print the...
分类:
其他好文 时间:
2014-09-14 11:22:47
阅读次数:
181
7.4Write methods to implement the multiply, subtract, and divide operations for integers. Use only the add operator.比较简单。但是要封装得好。7.5 Given two squares...
分类:
其他好文 时间:
2014-09-14 11:17:07
阅读次数:
189
http://poj.org/problem?id=1860DescriptionSeveral currency exchange points are working in our city. Let us suppose that each point specializes in two p...
分类:
其他好文 时间:
2014-09-13 20:08:45
阅读次数:
410
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 1 /** 2 ...
分类:
其他好文 时间:
2014-09-13 20:03:15
阅读次数:
228
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical an...
分类:
其他好文 时间:
2014-09-13 20:00:55
阅读次数:
146
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 ...
分类:
其他好文 时间:
2014-09-13 20:00:35
阅读次数:
207
MedianTime Limit:1000MSMemory Limit:65536KTotal Submissions:3866Accepted:1130DescriptionGivenNnumbers,X1,X2, ... ,XN, let us calculate the difference ...
分类:
其他好文 时间:
2014-09-13 10:34:44
阅读次数:
236
Description
Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponenti...
分类:
其他好文 时间:
2014-09-13 09:23:34
阅读次数:
197
TWO NODESTime Limit: 24000/12000 MS (Java/Others)Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 1137Accepted Submission(s): 333Problem ...
分类:
其他好文 时间:
2014-09-12 23:27:14
阅读次数:
330