leetcode 122. Best Time to Buy and Sell Stock II

Orignal question can be found here.

My solution is as follows:

int maxProfit(int* prices, int pricesSize)
{
  int result = 0;
  for (int i=1; i<pricesSize; ++i)
    if(prices[i]-prices[i-1]>0)
      result+=prices[i]-prices[i-1];

  return result;
}

Leave a Reply

Your email address will not be published. Required fields are marked *