1. 程式人生 > >LeetCode122買賣股票的最佳時機 II

LeetCode122買賣股票的最佳時機 II

 

int maxProfit(int* prices, int pricesSize) {
    int profit = 0;
    int i, j;
    for(i = 0; i < pricesSize - 1; i++)
        for(j = i + 1; j < pricesSize; j++)
        {
            if(prices[i] < prices[j]){
                profit += prices[j] - prices[i]; 
                break;          }
        }
    return profit;
}