Skip to content

Instantly share code, notes, and snippets.

@sreeprasad
Created November 11, 2014 10:59
Show Gist options
  • Save sreeprasad/621631057ea6799cee4c to your computer and use it in GitHub Desktop.
Save sreeprasad/621631057ea6799cee4c to your computer and use it in GitHub Desktop.
Best Time to Buy and Sell Stock II
public int maxProfit(int[] prices) {
int maxProfit=0;
for(int i=1;i<prices.length;i++){
if( (prices[i]-prices[i-1])>0 ){
maxProfit += prices[i]-prices[i-1];
}
}
return maxProfit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment