小黑代码
class Solution:
def maxProfit(self, prices: List[int]) -> int:
# 数组长度
n = len(prices)
# 最大利润
profit = 0
# 中间变量
min_ = prices[0]
# 遍历每一个数据作为买点
for i in range(1, n):
# 滚动获取最小值
if prices[i] - min_ > profit:
profit = prices[i] - min_
if prices[i] < min_:
min_ = prices[i]
return profit
数据库练习
584. 寻找用户推荐人
小黑代码
# Write your MySQL query statement below
SELECT
name
FROM
Customer
WHERE
referee_id != '2' OR referee_id IS NULL
pandas练习
176. 第二高的薪水
小黑代码
import pandas as pd
def second_highest_salary(employee: pd.DataFrame) -> pd.DataFrame:
data = employee['salary'].tolist()
data = set(data)
if len(data) >= 2:
target = sorted(data)[-2]
return pd.DataFrame(data=[[target]], columns=['SecondHighestSalary'])
return pd.DataFrame(data=[[None]], columns=['SecondHighestSalary'])
import pandas as pd
def second_highest_salary(employee: pd.DataFrame) -> pd.DataFrame:
# 删除重复数据
salary = employee[['salary']].drop_duplicates(['salary'])
# 少于两个的返回
if len(salary) < 2:
return pd.DataFrame({'SecondHighestSalary':[np.NaN]})
# 降序排列
salary = salary.sort_values('salary', ascending=False)
# 重命名
salary.rename({'salary': 'SecondHighestSalary'}, axis=1, inplace=True)
# 返回
return salary.head(2).tail(1)
多线程练习
1114. 按序打印
使用 synchronization
from threading import Lock
class Foo:
def __init__(self):
# 初始化锁
self.firstDone = Lock()
self.secondDone = Lock()
# 申请锁
self.firstDone.acquire()
self.secondDone.acquire()
def first(self, printFirst: 'Callable[[], None]') -> None:
# printFirst() outputs "first". Do not change or remove this line.
printFirst()
# 释放锁
self.firstDone.release()
def second(self, printSecond: 'Callable[[], None]') -> None:
with self.firstDone:
# printSecond() outputs "second". Do not change or remove this line.
printSecond()
self.secondDone.release()
def third(self, printThird: 'Callable[[], None]') -> None:
with self.secondDone:
# printThird() outputs "third". Do not change or remove this line.
printThird()
小黑生活
11点午餐干饭,准备出发跳操
出发参加比赛
到达奥体中心
进入会场完成比赛
小汤3《古老的曲调》打卡
健身房自行锻炼,练背部
早餐干饭
参加学术会议
12点40午餐干饭