File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change 1+ #include <limits.h>
12#include <stdio.h>
23#include <stdlib.h>
34
@@ -11,6 +12,10 @@ static double fast_pow(double x, int n)
1112
1213static double my_pow (double x , int n )
1314{
15+ if (n == INT_MIN ) {
16+ double t = 1 / fast_pow (x , - (n / 2 ));
17+ return t * t ;
18+ }
1419 return n < 0 ? 1 / fast_pow (x , - n ) : fast_pow (x , n );
1520}
1621
Original file line number Diff line number Diff line change @@ -21,11 +21,21 @@ static int dfs(int n, int *count)
2121
2222static int climbStairs (int n )
2323{
24+ #if 0
2425 int * count = malloc ((n + 1 ) * sizeof (int ));
2526 memset (count , 0 , (n + 1 ) * sizeof (int ));
2627 count [1 ] = 1 ;
2728 count [2 ] = 2 ;
2829 return dfs (n , count );
30+ #else
31+ int i , a = 1 , b = 2 , c ;
32+ for (i = 3 ; i <= n ; i ++ ) {
33+ c = a + b ;
34+ a = b ;
35+ b = c ;
36+ }
37+ return n == 1 ? a : (n == 2 ? b : c );
38+ #endif
2939}
3040
3141int main (int argc , char * * argv )
You can’t perform that action at this time.
0 commit comments