LeetCode练题——53. Maximum Subarray

Posted smart-cat

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode练题——53. Maximum Subarray相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode练题——118. Pascal's Triangle

[LeetCode] 53. Maximum Subarray

leetcode 53. Maximum Subarray

#Leetcode# 53. Maximum Subarray

LeetCode 53. Maximum Subarray

leetcode 53. Maximum Subarray