Total Accepted: 105799 Total Submissions: 297504 Difficulty: Easy Contributors: Admin 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?
思路就是从头到尾数一遍,找到该层
class Solution(object):
def getRow(self, rowIndex):
"""
:type rowIndex: int
:rtype: List[int]
"""
tmp = [
1]
i =
0
while(i != rowIndex):
tmp = map(
lambda x, y: x+y, tmp+[
0], [
0]+tmp)
i +=
1
return tmp
转载请注明原文地址: https://ju.6miu.com/read-17328.html