leetcode 122. 买卖股票的最佳时机 II

leetcode 122. 买卖股票的最佳时机 II_第1张图片


int maxProfit(int* prices, int pricesSize) {
    int i,max=0;
	for (i = 1; i < pricesSize; i++)
	{   
		if (prices[i]>prices[i-1])
		{
			max=max+prices[i]-prices[i-1];
		}
	}
	return max;
    
}int maxProfit(int* prices, int pricesSize) {
    int i,max=0;
	for (i = 1; i < pricesSize; i++)
	{   
		if (prices[i]>prices[i-1])
		{
			max=max+prices[i]-prices[i-1];
		}
	}
	return max;
  
}
#include 
int maxProfit(int* prices, int pricesSize) 
{
	int i,max=0;
	for (i = 1; i < pricesSize; i++)
	{   
		if (prices[i]>prices[i-1])
		{
			max=max+prices[i]-prices[i-1];
		}
	}
	return max;
}
int main(void)
{   int max;
	int arr[6]={7,1,5,3,6,4};
	max=maxProfit(arr,6);
	printf("%d",max);
	return 0;
}


你可能感兴趣的:(LeetCode)