严氏北美IT公司面试真题汇总和解答论坛
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Climbing Stairs

Go down

Climbing Stairs Empty Climbing Stairs

Post by Admin Sat Oct 21, 2017 4:58 pm

int climbStairs(int n) {
int f1 = 2;
int f2 = 1;
if(n == 1) {
return f2;
} else if(n == 2) {
return f1;
}

int fn=0;
for(int i = 3; i <= n; i++) {
fn = f1 + f2;
f2 = f1;
f1 = fn;
}
return fn;
}

Admin
Admin

Posts : 124
Join date : 2017-10-21

https://csinterviewquestions.forumotion.com

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum