码迷,mamicode.com
首页 > 其他好文 > 详细

LeetCode练题——53. Maximum Subarray

时间:2020-03-02 01:09:35      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:pre   nim   code   lse   style   where   subarray   site   start   

1、题目

Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal‘s triangle.

Note that the row index starts from 0.

技术图片
In Pascal‘s triangle, each number is the sum of the two numbers directly above it.

2、我的解答

 1 # -*- coding: utf-8 -*-
 2 # @Time    : 2020/3/1 21:57
 3 # @Author  : SmartCat0929
 4 # @Email   : 1027699719@qq.com
 5 # @Link    : https://github.com/SmartCat0929
 6 # @Site    : 
 7 # @File    : 119. Pascal‘s Triangle II.py
 8 
 9 from typing import List
10 
11 
12 class Solution:
13     def getRow(self, rowIndex: int) -> List[int]:
14         if 0 <= rowIndex <= 33:
15             c = []
16             c.append(1)
17             if rowIndex == 0:
18                 return c
19             for i in range(1, rowIndex + 1):
20                 c2 = []
21                 for j in range(i + 1):
22                     if 1 <= j < i:
23                         c2.append(c[i - 1][j - 1] + c[i - 1][j])
24                     else:
25                         c2.append(1)
26                 c.append(c2)
27             return c[rowIndex]
28         else:
29             return 0
30 
31 
32 print(Solution().getRow(0))

 

LeetCode练题——53. Maximum Subarray

标签:pre   nim   code   lse   style   where   subarray   site   start   

原文地址:https://www.cnblogs.com/Smart-Cat/p/12392989.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!