public class Solution
{
public int MaxProfit(int[] prices)
{
int max = 0;
int n = prices.Length;
int i = 0, j = 1;
while (i < n && j < n && i < j)
{
while (j < n && prices[j] > prices[j-1])
j++;
max += (prices[j - 1] - prices[i]);
i = j;
j = i + 1;
}
return max;
}
}
{
public int MaxProfit(int[] prices)
{
int max = 0;
int n = prices.Length;
int i = 0, j = 1;
while (i < n && j < n && i < j)
{
while (j < n && prices[j] > prices[j-1])
j++;
max += (prices[j - 1] - prices[i]);
i = j;
j = i + 1;
}
return max;
}
}