Implement pow(x,n).思路:像string to integer一样。考虑的细节较多。 1.测试用例要考虑基数和指数都为正数、负数和零的情况。 2.注意0的0次方在数学上没有意义。 3.用位运算代替乘除和求余优化效率:移位代替除法(n>>1 == n /2);用位与代替求...
分类:
其他好文 时间:
2014-11-26 22:15:49
阅读次数:
182
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the valu...
分类:
系统相关 时间:
2014-11-26 18:35:59
阅读次数:
215
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41346969
Implement strStr().
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
Update (2014-11-02):
The signature of the function...
分类:
其他好文 时间:
2014-11-24 22:37:49
阅读次数:
224
//MFCDynimic.cpp:Definestheentrypointfortheconsoleapplication.///*运行时类信息机制:在程序运行过程中,可以判断类对象的相关类的信息以及继承派生类。*/#include"stdafx.h"#include"MFCDynimic.h"classCAnimal:publicCObject{DECLARE_DYNAMIC(CAnimal);};IMPLEMENT_DYNAM..
分类:
其他好文 时间:
2014-11-23 16:06:12
阅读次数:
154
In Java, if you want your own class to be a valid key type of the container, you just need to make it implement the interface "Comparable", and then i...
分类:
编程语言 时间:
2014-11-22 22:51:01
阅读次数:
272
求1+2+3+...+n,编程实现,但是不允许用if,while,for,?等语句,也不能用乘除法。当然肯定也不允许用pow这样的函数了。...
分类:
其他好文 时间:
2014-11-22 09:23:17
阅读次数:
176
int类型范围 -2147483648~2147483647
当n=-2147483648,则-n=2147483648超出2147483647,结果仍然是-2147483648,所以应该单独处理。
也可以用机器码来解释这一个知识点:-2147483648的机器吗为1000...0000(32位),取负,即机器码各位取反后加1,得到的还是100....000。这也是代码中if(n<0 && n!=INT_MIN) return 1.0/pow(x,-n) 为什么这样写的原因,如果写成if(n<0) retu...
分类:
其他好文 时间:
2014-11-22 09:21:59
阅读次数:
220
LRU CacheDesign and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get...
分类:
系统相关 时间:
2014-11-21 18:21:45
阅读次数:
238
Implement int sqrt(int x).
Compute and return the square root of x.
原题链接:https://oj.leetcode.com/problems/sqrtx/
使用二分法来解题。
public int sqrt(int x) {
if(x == 0 || x== 1)
return x;
in...
分类:
其他好文 时间:
2014-11-21 16:24:07
阅读次数:
175
Implement pow(x,n).C++实现代码:#includeusing namespace std;class Solution{public: double pow(double x, int n) { if(x==0&&n==0) ret...
分类:
其他好文 时间:
2014-11-21 10:36:20
阅读次数:
147