Skip to content

Instantly share code, notes, and snippets.

@Cee
Created May 29, 2014 00:39
Show Gist options
  • Save Cee/14ad4a37cc8216e27ce6 to your computer and use it in GitHub Desktop.
Save Cee/14ad4a37cc8216e27ce6 to your computer and use it in GitHub Desktop.
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;
}
}
@Cee
Copy link
Author

Cee commented May 29, 2014

嘛 简单的贪心。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment