Algorithm
只能买卖一次(dp)
class Solution:
def maxProfit(self, prices: List[int]) -> int:
if not prices:
return 0
res = 0
minbuy = prices[0]
for i in range(len(prices)):
res = max(res,prices[i]-minbuy)
minbuy = min(minbuy,prices[i])
return res
可以多次买卖(贪心)
class Solution:
def maxProfit(self, prices: List[int]) -> int:
mp = 0
for i in range(1,len(prices)):
d = prices[i]-prices[i-1]
if d>0:
mp+=d
return mp
Review
https://medium.com/@george3d6/the-success-of-go-heralds-that-of-rust-73cb2e4c0500
go 和 rust 的比较
Tip
-
JS 跳转到指定位置
Element.scrollIntoView()
参见:https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
-
显示 dd 命令的进度
用 dd 命令制作系统安装盘时,显示进度。
参见:https://apple.stackexchange.com/questions/234167/how-can-i-track-progress-of-dd
Share
- Redis 命令参考,全面的手册,官方文档翻译。
- 阿里云前端技术周刊
- SQL 教程,循序渐进的学习 SQL
- 在 rust 中直接写 python 代码