题解 | #买卖股票的最好时机(二)#
买卖股票的最好时机(二)
https://www.nowcoder.com/practice/fbc5dad3e215457fb82a3ae688eb7281
#include <iostream> using namespace std; const int N = 1e5 + 10; int prices[N]; int main() { int n; cin >> n; for(int i = 0;i < n; i++) cin >> prices[i]; int retsum = 0; for(int i = 1;i < n; i++) { if(prices[i] - prices[i-1] > 0) retsum += (prices[i] - prices[i-1]); } cout << retsum << endl; return 0; }