class Solution:
def maxProfit(self, prices: List[int], fee: int) -> int:
# 数组长度
n = len(prices)
if n < 2:
return 0
# 动态规划变量
buy = -prices[0]
sell = 0
for i in range(1, n):
buy = max(buy, sell-prices[i])
sell = max(sell, buy+prices[i]-fee)
return sell

class Solution:
def maxProfit(self, prices: List[int], fee: int) -> int:
# 数组长度
n = len(prices)
if n < 2:
return 0
# 初始化贪心算法起点
pre_price = prices[0] + fee
# 利润
profit = 0
# 开始贪心算法
for i in range(1, n):
if prices[i] > pre_price:
profit += (prices[i]-pre_price)
pre_price = prices[i]
elif prices[i] + fee < pre_price:
pre_price = prices[i] + fee
return profit

小黑代码
# Write your MySQL query statement below
SELECT
class
FROM
Courses
GROUP BY
class
HAVING
COUNT(student) >= 5
小黑代码
import pandas as pd
def find_classes(courses: pd.DataFrame) -> pd.DataFrame:
df = courses.groupby('class').size().reset_index(name='count')
df = df[df['count']>=5]
return df[['class']]

































