• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
村雨sup
自己选的路,跪着也要走完 XD
博客园    首页    新随笔    联系   管理    订阅  订阅
Leetcode 109
//这种也是空间复杂度为O(K)的解法,就是边界有点难写
class
Solution { public: vector<int> getRow(int rowIndex) { vector<int> res; res.push_back(1); if(rowIndex == 0) return res; res.push_back(1); if(rowIndex == 1) return res; for(int i=2;i <= rowIndex;i++){ res.push_back(0); int a = res[0]; int b = res[1]; for(int j=1;j < i;j++){ res[j] = a+b; a = b; b = res[j+1]; } res[i] = 1; } return res; } };

 

posted on 2019-02-03 17:47  村雨sup  阅读(79)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3