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, whe...
分类:
其他好文 时间:
2014-06-09 23:14:45
阅读次数:
264
题目
Two elements of a binary search tree (BST) are swapped by mistake.
Recover the tree without changing its structure.
Note:
A solution using O(n)
space is pretty straight forward. Cou...
分类:
其他好文 时间:
2014-06-08 15:32:45
阅读次数:
245
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 link...
分类:
其他好文 时间:
2014-06-08 15:30:28
阅读次数:
227
先上写干货,几个开源网站:
github.com
launchpad.netgitorious.orgsourceforge.netfreecode.com
今天介绍一下python函数和文件读写的知识。
函数
def print_two(*args):#That tells Python to take all the arguments to the function a...
分类:
编程语言 时间:
2014-06-08 10:37:23
阅读次数:
277
题目...For example,Given input array A = [1,1,2],Your function should return length = 2, and A is now [1,2].
解题思路,
移除数组中的重复元素,并返回新数组的长度。
这个题目应该算是简单的题目。使用两个变量就可以。具体的看代码
代码实现......
分类:
其他好文 时间:
2014-06-08 03:54:22
阅读次数:
279
求两个排序数组的中位数。这个题可以有以下几个思路:
首先可以想到的是将两个数组merge起来,然后返回其中位数。
第二个是,类似merge的思想加上计数,找到(m+n)/2个数或者其前后的数,这个就可以算出中位数。这个方法对于各种情况需要一一考虑到。
第三个,假设A[k/2-1]<B[k/2-1],那么A[k/2-1]之前的数一定在整个有序数列中(m+n)/2之前。
这里我给出后面两种思路的代码。
代码一( 思路三)...
分类:
其他好文 时间:
2014-06-08 03:44:47
阅读次数:
231
Problem Description
A hat’s word is a word in the dictionary that is the concatenation of exactly two other words in the dictionary.
You are to find all the hat’s words in a dictionary.
In...
分类:
其他好文 时间:
2014-06-08 03:02:14
阅读次数:
323
题目 :Input: numbers={2, 7, 11, 15}, target=9
Output: index1=1, index2=2
解题思路:
给出一个数组合一个数,如果两个数的和等于所给的数,求出该两个数所在数组中的位置。
这个题也挺常见的,就是两个指针,从前后两个方向扫描。但是本题有以下几个需要的点:
1. 所给数组不是有序的;
2. 返回的下标是从1开始的,并且是原来无序数组中的下标;
3. 输入数组中可能含有重复的元素。
好了,把以上三点想到的话,做这个题应该不会有啥问题。
具体方法:把原...
分类:
其他好文 时间:
2014-06-08 02:14:06
阅读次数:
250
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, whe...
分类:
其他好文 时间:
2014-06-08 02:12:04
阅读次数:
216
Givennnon-negative integersa1,a2, ...,an, where
each represents a point at coordinate (i,ai).nvertical lines are drawn such that
the two endpoints of ...
分类:
其他好文 时间:
2014-06-07 23:03:35
阅读次数:
279