LeetCode OJ——Pascal's Triangle II
http://oj.leetcode.com/problems/pascals-triangle-ii/
杨辉三角2,比杨辉三角要求的空间上限制Could you optimize your algorithm to use only O(k) extra space?其实计算当前行,也只用到前一行了。再前面的没有用。
class Solution {
public:
vector<int> getRow(int rowIndex) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
vector<int> onepiece;
if(rowIndex<)
return onepiece;
//
onepiece.push_back();
if(rowIndex == )
return onepiece;
//
onepiece.push_back();
if(rowIndex == )
return onepiece;
//2...
vector<int> ans(onepiece);
for(int row = ;row<= rowIndex;row++)
{
onepiece = ans;
for(int index = ;index < row;index++)
{
ans[index] = onepiece[index - ]+onepiece[index];
}
ans.push_back();
}
return ans;
}
};
LeetCode OJ——Pascal's Triangle II的更多相关文章
- 【LeetCode】Pascal's Triangle II 解题报告
[LeetCode]Pascal's Triangle II 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/pascals-tr ...
- [LeetCode] 119. Pascal's Triangle II 杨辉三角 II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- [LeetCode] 119. Pascal's Triangle II 杨辉三角之二
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note t ...
- LeetCode 119. Pascal's Triangle II (杨辉三角之二)
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- leetcode 【 Pascal's Triangle II 】python 实现
题目: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [ ...
- 【leetcode】Pascal's Triangle II
题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...
- LeetCode 119 Pascal's Triangle II
Problem: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Ret ...
- leetcode 119 Pascal's Triangle II ----- java
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- Java [Leetcode 119]Pascal's Triangle II
题目描述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return ...
随机推荐
- 实验二 JSP基本动态元素的使用
实验二 JSP基本动态元素的使用 实验性质:验证性 实验学时: 2学时 实验地点: 一 .实验目的与要求 1.掌握JSP中声明变量.定义方法.java程序片及表达式的使 ...
- 科学计算库Numpy——概述
Numpy主要用于数组的各种计算. 导入Numpy import numpy as np 数组类型 Numpy的数组类型为numpy.ndarray. array=np.array([1,2,3,4, ...
- python-闭包函数和装饰器
目录 闭包函数 什么是闭包? 两种为函数传参的方式 使用参数的形式 包给函数 闭包函数的应用 闭包的意义: 装饰器 无参装饰器 什么是装饰器 为什么要用装饰器 怎么用装饰器 完善装饰器 闭包函数 什么 ...
- 探讨2018年最受欢迎的15顶级Python库!
近日,数据科学网站 KDnuggets 评选出了顶级 Python 库 Top15,领域横跨数据科学.数据可视化.深度学习和机器学习.如果本文有哪些遗漏,你可以在评论区补充. 图 1:根据 GitHu ...
- 水题:CF16C-Monitor
Monitor 题目描述 Reca company makes monitors, the most popular of their models is AB999 with the screen ...
- poj 2236 网络连接问题 并查集
题意:n台电脑,当两台之间的距离小于d的时候可以连接. 题目会进行操作“修复”还有“查询是否已经连接”.只要在查询的时候输出YES或者ON 思路: 把可以相互连接的 即两者之间的距离小于 d q[i ...
- XenServer 6.5 安装
为了方便截图我下面的所有操作都是在VMware Workstation 11 上面完成的,但在之后的所有Citrix产品的操作中都将会在物理环境完成,物理机安装XS的步骤和下面是相同的. 1.打开Wo ...
- dataTable组件使用
dataTable组件使用:引入JS $("#id").DataTable({ scrollY:450, //开始滚动高度 lengthChange:false , // ...
- 05-python进阶-简单监控程序开发
#!/usr/bin/env python #coding:utf-8 ''' 监控监控程序 ''' import json import urllib import inspect import o ...
- Get Sauce(状压DP)
描述 In order to celebrate the 8th anniversary of ZOJ, LCLL goes to a sauce factory to "Get Sauce ...