题解 | #买卖股票的最好时机(一)#
买卖股票的最好时机(一)
https://www.nowcoder.com/practice/351b87e53d0d44928f4de9b6217d36bb
#include <iostream> #include <vector> using namespace std; int main() { int n = 0; cin >> n; vector<int> arr(n); int m = 0; while(n--) { cin >> arr[m]; m++; } int minval = arr[0]; int submax = 0; for(int i = 0;i<arr.size();i++) { minval = min(arr[i],minval); submax = max(submax, arr[i] - minval); } cout << submax << endl; return 0; }