打表,学神,回归,题解

魈凯KBS  •  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 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; }


Comments:

我真的笑死,两个人一毛一样的题解( 格式都一样丑 )


刘嘉柚  •  2个月前