标签:
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?
Subscribe to see which companies asked this question
解题分析:
此处有空间的限制,因此不能正常使用迭代算法,
这里推荐滚动数组思想,具体思想在我的上一篇博客里有写。
# -*- coding:utf-8 -*- __author__ = 'jiuzhang' class Solution(object): def getRow(self, rowIndex): if rowIndex < 0: return [] result = [0] * (rowIndex + 1) for i in range(rowIndex + 1): result[i] = 1 for j in xrange(i - 1, 0, -1): result[j] += result[j - 1] return result
(LeetCode)Pascal's Triangle II --- 杨辉三角进阶(滚动数组思想)
标签:
原文地址:http://blog.csdn.net/u012965373/article/details/52180940