摘要:
Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary search tree.You may assume each number in the sequ... 阅读全文
posted @ 2015-10-22 03:15
茜茜的技术空间
阅读(225)
评论(0)
推荐(0)
摘要:
Implementint sqrt(int x).Compute and return the square root ofx.解题思路:对于一个非负数n,它的平方根不会大于(n/2+1)。在[0, n/2+1]这个范围内可以进行二分搜索(binary search),求出n的平方根。注:在中间过程... 阅读全文
posted @ 2015-10-22 01:16
茜茜的技术空间
阅读(185)
评论(0)
推荐(0)
摘要:
Implement pow(x,n).解题思路:pow(x,n)就是求x的n次方。x的N次方可以看做:x^n = x^(n/2)*x^(n/2)*x^(n%2)。所以利用递归求解,当n==1的时候,x^n=x。当然n是可以小于0的,2^(-3) = 1/(2^3)。按照上面那个规律就可以解决了。Ja... 阅读全文
posted @ 2015-10-22 01:01
茜茜的技术空间
阅读(129)
评论(0)
推荐(0)
摘要:
Given an array containingndistinct numbers taken from0, 1, 2, ..., n, find the one that is missing from the array.For example,Givennums=[0, 1, 3]retur... 阅读全文
posted @ 2015-10-22 00:47
茜茜的技术空间
阅读(242)
评论(0)
推荐(0)

浙公网安备 33010602011771号