• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
neverlandly
博客园    首页    新随笔    联系   管理    订阅  订阅
2014年5月20日
Leetcode: Climbing Stairs
摘要: 这道题目是求跑楼梯的可行解法数量。每一步可以爬一格或者两个楼梯,可以发现,递推式是f(n)=f(n-1)+f(n-2),也就是等于前一格的可行数量加上前两格的可行数量。熟悉的朋友可能发现了,这个递归式正是斐波那契数列的定义. 这里base case 是f(1)=1, f(2)=2. Fibonacc 阅读全文
posted @ 2014-05-20 07:10 neverlandly 阅读(380) 评论(0) 推荐(0)
Leetcode: Set Matrix Zeroes
摘要: 一次过,空间复杂度为O(m+n), 下一次做的时候寻找constant space solution。用boolean array也可以,用bit vector可能会更节省. 其实还可以再优化,我们考虑使用第一行和第一列来记录上面所说的行和列的置0情况,这里问题是那么第一行和第一列自己怎么办?想要记 阅读全文
posted @ 2014-05-20 07:08 neverlandly 阅读(311) 评论(0) 推荐(0)
Leetcode: Search a 2D Matrix
摘要: 1 Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: 2 3 Integers in each row are ... 阅读全文
posted @ 2014-05-20 06:56 neverlandly 阅读(360) 评论(0) 推荐(0)
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3