题解 | #NC7-买卖股票的最好时机#
买卖股票的最好时机
http://www.nowcoder.com/practice/64b4262d4e6d4f6181cd45446a5821ec
class Solution {
public:
/**
*
* @param prices int整型vector
* @return int整型
*/
int maxProfit(vector<int>& prices) {
// write code here
if(prices.size() <= 1)
return 0;
int mProfit = 0;
for(int i = 1; i < prices.size(); i++){
for(int j = 0; j < i; j++){
mProfit = max(mProfit, prices[i]-prices[j]);
}
}
return mProfit;
}
};
顺丰集团工作强度 312人发布