题意:给定两个代表数字的链表,每个节点里存放一个digit,数字是逆方向的,将这两个链表相加起来
思路:
1.i, j遍历l1,l2至最长,短的补零
2..设置一个进位变量c, 第i次遍历 l1,l2,c的和除以10进位,mod10留在这一位
3.出循环后还要检查是不是还有进位
复杂度:O(m+n), 空间O(m+n)...
分类:
其他好文 时间:
2014-05-15 13:38:03
阅读次数:
258
给一个素数x,和a1、a2……an,计算这个式子 的时候,化成了 这个形式, 且t等于 xa1?+?a2?+?...?+?an,求s和t的最大公约数
(1?≤?n?≤?105, 2?≤?x?≤?109) ,结果对1000000007 取模...
分类:
其他好文 时间:
2014-05-15 13:04:46
阅读次数:
291
Two SumGiven an array of integers, find two
numbers such that they add up to a specific target number.The function twoSum
should return indices of the...
分类:
其他好文 时间:
2014-05-15 10:48:59
阅读次数:
322
【题目】
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.
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Out...
分类:
其他好文 时间:
2014-05-15 05:13:49
阅读次数:
306
LeetCode-001 Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.
The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2...
分类:
其他好文 时间:
2014-05-15 04:34:50
阅读次数:
293
Humble Numbers
题目描述
A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ... shows the fi...
分类:
其他好文 时间:
2014-05-15 01:36:22
阅读次数:
230
Description
Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or phrase. For example, you can call the Universit...
分类:
其他好文 时间:
2014-05-15 00:20:39
阅读次数:
332
[ 问题: ]
Given an array of integers, find two numbers such that they add up to a specific target number.
The function twoSum should return indices of the two numbers such that they add up to the ta...
分类:
其他好文 时间:
2014-05-15 00:04:39
阅读次数:
377
Given two numbers represented as strings,
return multiplication of the numbers as a string.Note: The numbers can be
arbitrarily large and are non-nega...
分类:
其他好文 时间:
2014-05-14 23:11:14
阅读次数:
398
这题跟上两题也差不多。把150以内的素数找出来,把素数的值看做硬币的面值,每个硬币的个数即ceil(150/prime[i]),因为再多也没用,最多组成n=150就行了,所以又回到了找硬币问题。用生成函数解之。代码:#include
#include #include #include #inclu...
分类:
其他好文 时间:
2014-05-14 22:43:11
阅读次数:
404