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


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 <stdio.h>
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;
}


猜你喜欢

转载自blog.csdn.net/ychhh/article/details/80374662
今日推荐