今際の国の呵呵君
Thursday, January 8, 2015
[LeetCode]Climbing Stairs
DP和递归解法。值得一提的是DP只需要用前两个数,所以不需要开辟数组,constant space。f[i]代表爬到第i个阶梯的时候有多少种方法
f[i] = f[i - 1] + f[i - 2]
f[0] = f[1];
f[1] = f[1];
DP代码如下:
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment