Why Memory Limit Exceeded? It seems results are correct.

```
public class Solution {
public int MaxProfit(int[] prices) {
if (prices.Length <= 1)
return 0;
int buyPrice = prices[0];
int salePrice = 0;
int j = 1;
while (j < prices.Length && buyPrice > prices[j] )
{
buyPrice = prices[j];
j++;
if (j >= prices.Length)
break;
}
if ( buyPrice == prices[0] && j >= prices.Length)
return 0;
salePrice = buyPrice;
while (j < prices.Length && salePrice < prices[j])
{
salePrice = prices[j];
j++;
if (j >= prices.Length)
break;
}
if (prices.Length - j == 0)
return salePrice - buyPrice;
int[] newPrices = new int[prices.Length - j];
for (int i = 0; i < newPrices.Length; i++, j++)
newPrices[i] = prices[j];
return salePrice - buyPrice + MaxProfit(newPrices);
}
}
```