题目: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....
分类:
编程语言 时间:
2014-08-05 05:17:28
阅读次数:
265
Metric spaces is a large class of spaces on which the closeness of two points is depicted by a distance function, or called a metric. Metric spaces ar...
分类:
其他好文 时间:
2014-08-05 03:04:28
阅读次数:
220
题目原文:
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 ...
分类:
其他好文 时间:
2014-08-05 00:51:58
阅读次数:
257
Problem Description:
Divide two integers without using multiplication, division and mod operator.
分析:题目意思很容易理解,就是不用乘除法和模运算求来做除法,很容易想到的一个方法是一直做减法,然后计数,但是提交之后显示超时,在网上找到一种解法,利用位运算,意思是任何一个整数可以表示成以2的幂为...
分类:
其他好文 时间:
2014-08-04 21:33:28
阅读次数:
307
BestCoder Sequence
Problem Description
Mr Potato is a coder.
Mr Potato is the BestCoder.
One night, an amazing sequence appeared in his dream. Length of this sequence is odd, the median...
分类:
其他好文 时间:
2014-08-04 17:42:57
阅读次数:
282
题目:Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-....
分类:
编程语言 时间:
2014-08-04 13:58:57
阅读次数:
285
Then-queens puzzle is the problem of placingnqueens on ann×nchessboard such that no two queens attack each other.Given an integern, return all distinc...
分类:
其他好文 时间:
2014-08-04 13:31:07
阅读次数:
250
题意:求一串数字里的中位数。内存为1M。每个数范围是0到2的31次方-1。思路:很容易想到把数字全部读入,然后排序,但是会超内存。用计数排序但是数又太大。由于我们只需要第n/2、n/2+1大(n为偶数)或第(n+1)/2大(n为奇数)。所以可以用优先队列来维护最值,这样只需要存一半元素(n/2+1个...
分类:
其他好文 时间:
2014-08-04 13:29:27
阅读次数:
215
题目:Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".题解:二进制加法都是从最低位(从右加到左)。所以对两个字符串要从最后一位开始加,....
分类:
编程语言 时间:
2014-08-04 06:13:36
阅读次数:
291
题目: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 ....
分类:
编程语言 时间:
2014-08-04 04:10:46
阅读次数:
309