Markdown+pandoc打造CDSP自成长备考资料库,告别资料混乱
2026/10/15 10:56:26
题目地址:链接
思路:遍历时记录最小值,当前值减去历史最小值
functionmaxProfit(prices:number[]):number{letans=0letlastMin=prices[0]for(constpriceofprices){lastMin=Math.min(lastMin,price)ans=Math.max(ans,price-lastMin)}returnans};