题解 | #买卖股票的最好时机(一)#
买卖股票的最好时机(一)
https://www.nowcoder.com/practice/351b87e53d0d44928f4de9b6217d36bb
a=input()#input 只能读取一行
n=int(a)
price=list(map(int,input().split()))
dp=[0]*n
###### 思路寻找前i个元素的最小值做dp
res=price[0]
for i in range(1,n):
if price[i]<res:
dp[i]=0
res=price[i]
else:
dp[i]=price[i]-res
print(max(dp))
查看17道真题和解析
