小黑代码(独立做出)
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
数据库练习
596. 超过5名学生的课
小黑代码
# Write your MySQL query statement below
SELECT
class
FROM
Courses
GROUP BY
class
HAVING
COUNT(student) >= 5
pandas练习
小黑代码
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']]
小黑生活
跟中老黑和阿黄一起喝酒吃知了蚕蛹去啦,阿黄带了他家酿的茅台,舒服~得知大家工作都有发展福利也都不错,小黑十分开心
中老黑请我们喝了茶百道
早餐鸡蛋灌饼加里脊
两个马拉松全中了,可惜是同一天,打算跑怀柔
买瓶饮料去图书馆坐坐,碰到了尚香
买的东西到啦,能量胶,石榴汁
受到了学弟的鼓舞,刚开始还没我跑的快,现在都练到二级了,这份热爱值得我去学习
健身课前一个人涮羊肉
健身课打卡,练腿,这个月第二次丢耳机,又损失了259,这个月一共损失超过500元了,打算再也不买超过60的耳机了,心态放平,莫内耗,要让自己变得越来越沉稳。
麦当劳早餐,地铁上刷科一