题意:给定两个代表数字的链表,每个节点里存放一个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
简单点说其实Segment Tree就是二分法的灵活运用。
需要的基础知识:
1 二分法
2 二叉树
3 最好熟悉堆排序
操作就是二分法和堆排序巧妙地合并起来。
有了这些基础知识Segment Tree就没有任何难度了。
参考原文:
http://www.geeksforgeeks.org/segment-tree-set-1-sum-of-given-range/
...
分类:
其他好文 时间:
2014-05-15 13:33:33
阅读次数:
250
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
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
# 非波拉锲数列def fibs(num): the_list=[] a,b,i=0,1,1 for
i in range(num-1): a,b=b,a+b print bfibs(10)
分类:
编程语言 时间:
2014-05-14 22:00:27
阅读次数:
290
实际上也是一个二分查找的问题。
要找出范围,决定了当找到这个数时不能马上返回,如果找target最前面的那个位置,只有当这个位置等于target,且这个位置的前一个位置不等于target时,才能返回这个位置。如果找的是target最后面的那个位置,那么只有当这个位置等于target,且这个位置的后一个位置不等于target时,才会返回它。不满足返回条件时,下一次递归走什么位置也不一样,找前面的时...
分类:
其他好文 时间:
2014-05-14 21:58:25
阅读次数:
350