题目: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3,3,1]. Note:Could you optimize your algorithm to use only O(k) extra space? 提示: 此题要求给出杨辉三角对应行号下的所有数字序列,且空间复杂度为O(n).这里我们可以根据杨辉三角的定义,逐行计算.顺序从左到右或者从右到…
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use onl…
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3,3,1]. Note:Could you optimize your algorithm to use only O(k) extra space? [思路] 我们为了满足空间复杂度的要求,我们新建两个ArrayList,一个负责存储上一个Pascal行的结果,一个根据上一个Pascal行得出当前P…
题目: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] 提示: 此题要求计算出给定行数的杨辉三角.只要摸清规律就并不难. 代码: class Solution { public: vector<vector<int> > genera…
1. 题目 1.1 英文题目 Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal's triangle. In Pascal's triangle, each number is the sum of the two numbers directly above it as shown: 1.2 中文题目 输出杨辉三角形的指定行 1.3输入输出 输入 输出 rowIndex = 3 [1,3…
原文题目: 118. Pascal's Triangle 119. Pascal's Triangle II 读题: 杨辉三角问题 '''118''' class Solution(object): def generate(self, numRows): """ :type numRows: int :rtype: List[List[int]] """ if not numRows: return [] result = [] for i i…