Created
November 11, 2014 10:59
-
-
Save sreeprasad/621631057ea6799cee4c to your computer and use it in GitHub Desktop.
Best Time to Buy and Sell Stock II
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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