买卖股票的最佳时机
class Solution { public: /** * @param prices: Given an integer array * @return: Maximum profit */ int maxProfit(vector<int> &prices) { // write your code here int maxprofit=0; int profit=0; int length=prices.size(); if(length==0) return 0; else { for(int i=0;i<length;i++) { for(int j=i+1;j<length;j++) if(prices[i]>=prices[j]) i=j; else { profit=prices[j]-prices[i]; if(maxprofit<profit) maxprofit=profit; } } return maxprofit; } } };