Hey guys! I have written this O(N) solution, but it seems to be 91% faster in comparision with the other submitted solution. Can someone please let me know a faster approach?
public int maxProfit(int[] prices) {
int i = 0;
int profit = 0;
for(int j = i + 1; j < prices.length; j++, i++){
if(prices[j] > prices[i]) profit += prices[j] - prices[i];
}
return profit;
}