[leetcode]#119. Pascal's Triangle II

来源:互联网 发布:js设置按钮隐藏 编辑:程序博客网 时间:2024/06/03 22:56

跟上一题一样,只是返回的值是指定的某一行
For example, given k = 3,
Return [1,3,3,1].

class Solution:      # @return a list of integers      def getRow(self, rowIndex):          rownum=rowIndex+1          currow=[1]          if rownum==1:              return currow          if rownum>0:              currow=[1]              for index in range(rownum):                  prerow=currow                  currow=[1]                  for j in range(index-1):                      currow.append(prerow[j]+prerow[j+1])                  currow.append(1)          return currow 
原创粉丝点击