摘要: 1 class Solution { 2 public: 3 bool equal( double a,double b ) 4 { 5 if( a-b -0.0000001 ) 6 { 7 return true; 8 } 9 else10 {11 return false;12 }13 }14 15 double pow_unsigned(double x,unsigned int n )16 {... 阅读全文
posted @ 2013-07-19 21:38 NinaGood 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 编程之美上也有这道题,但是个人觉得讲的并不是易懂,之后我在剑指offer上看到这道题看一遍就懂了;知识提取:一个整数n和n-1的与运算,获得整数n的二进制数最右边的1变0;int NumberOf1( int n ){ int num=0; while( n ) { n&=n-1; num++; } return num;} 详细内容参考剑指offer 阅读全文
posted @ 2013-07-19 14:42 NinaGood 阅读(72) 评论(0) 推荐(0) 编辑
摘要: 时间复杂度O(n) 1 long Fibonacci( long n ) 2 { 3 if( n <= 1 ) 4 return n; 5 6 long one=0; 7 long two=1; 8 9 for( long i = 2; i <= n; ++i )10 {11 int tmp = two;12 two += one;13 one = tmp;14 }15 return two;16 } 阅读全文
posted @ 2013-07-19 09:52 NinaGood 阅读(144) 评论(0) 推荐(0) 编辑