摘要: 逐个求,保存最大和。 如果前序和小于0则舍弃,始终以正值优先。 class Solution: def maxSubArray(self, nums: List[int]) -> int: cur = nums[0] maximum = nums[0] for i in range(1,len(nu 阅读全文
posted @ 2021-06-07 15:44 泊鸽 阅读(33) 评论(0) 推荐(0)
摘要: 从头遍历到尾两两计算,遇到最小换最小,逐个计算大利润,遇到大利润保存大利润 类似栈 效率高但是耗内存 class Solution: def maxProfit(self, prices: List[int]) -> int: if len(prices) <= 1: return 0 minimu 阅读全文
posted @ 2021-06-07 15:19 泊鸽 阅读(104) 评论(0) 推荐(0)
摘要: 1--1种 2--2种 3--3种 4--5种 5--8种 ………… 写一写发现类似斐波那契数列,后一项等于前两项之和 class Solution: def climbStairs(self, n: int) -> int: if n <= 2: return n a = 1 b = 2 whil 阅读全文
posted @ 2021-06-07 14:47 泊鸽 阅读(88) 评论(0) 推荐(0)