awa

baim.  •  2个月前


include

include

using namespace std; int maxProfit(vector& prices) {

int n = prices.size();
int ans = 0;
for (int i = 0; i < n; i++) {
	for (int j = i + 1; j < n; j++) {
		ans = max(ans, prices[j] - prices[i]);
	}
}
return ans;

} int main() {

vector<int> prices = { 7,1,5,3,6,4 };
cout << "The prices: ";
for(int i = 0; i < prices.size(); i++) {
	cout << prices[i] << " ";
}
cout << endl;
int ans = maxProfit(prices);
cout << "The max profit: " << ans << endl;
return 0;

}


评论:


 •  2个月前