题目
Implement pow(x, n).
方法
注意Integer.MIN_VALUE值和Integer.MAX_VALUE值。
public double pow(double x, int n) {
if (n == 0) {
return 1;
}
if (n == Integer.MIN_VAL...
分类:
其他好文 时间:
2014-06-19 10:37:27
阅读次数:
210
题目
Implement strStr().
Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.
方法
只需要遍历一遍即可。
public String strStr(String...
分类:
其他好文 时间:
2014-06-16 19:07:08
阅读次数:
188
Description:Implement pow(x, n)大意:实现pow(x, n),即通常所说的x的n次方。分析:真是一道很考验人的题目,看似简单,其实有非常多的细节要注意:1)由于x及返回值都是浮点数(double),那么许多自定义的变量、返回值都尽量使用#.0f的方式定义与实现,显得正式...
分类:
其他好文 时间:
2014-06-15 07:56:03
阅读次数:
213
LRU CacheDesign and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get...
分类:
其他好文 时间:
2014-06-14 23:54:37
阅读次数:
352
当集合或数组内的对象需要排序时,会利用Collections.sort或Arrays.sort来进行排序,通常会implement
Comparable,来实现自定义排序,透过回传值来表示排序的大小。
分类:
编程语言 时间:
2014-06-12 19:33:37
阅读次数:
239
二叉查换树,左孩子小于等于根,右孩子大于根。完全二叉树,叶子都在最后一层,所有结点(除了叶子)都有两个孩子。平衡二叉树,左右子树的高度在一定范围内。4.1
Implement a function to check if a binary tree is balanced. For the purp...
分类:
其他好文 时间:
2014-06-12 08:09:04
阅读次数:
167
3.1Describe how you could use a single array to
implement three stacks.Flexible
Divisions的方案,当某个栈满了之后,需要把相邻的栈调整好,这是一个递归的过程。每个stack有一些属性,所以不妨将每个stack封闭...
分类:
其他好文 时间:
2014-06-10 16:27:38
阅读次数:
234
Graph coloring is the problem of assigning a color to each vertex of an undirected graph such that no two adjacent vertices have the same color. We implement the greedy algorithm from Scalable parallel graph coloring algorithms. The algorithm iteratively f...
分类:
其他好文 时间:
2014-06-10 07:10:19
阅读次数:
260