Created
May 29, 2014 00:39
-
-
Save Cee/14ad4a37cc8216e27ce6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 class Solution { | |
public int maxProfit(int[] prices) { | |
int ret = 0; | |
int index = 0; | |
while (index < prices.length){ | |
if (index + 1 < prices.length){ | |
if (prices[index] < prices[index + 1]){ | |
ret += prices[index + 1] - prices[index]; | |
} | |
} | |
index++; | |
} | |
return ret; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
嘛 简单的贪心。