Skip to content

Instantly share code, notes, and snippets.

@Cee
Created May 29, 2014 07:00
Show Gist options
  • Save Cee/6591fb5e984508a463e9 to your computer and use it in GitHub Desktop.
Save Cee/6591fb5e984508a463e9 to your computer and use it in GitHub Desktop.
public class Solution {
public int maxProfit(int[] prices) {
int ret = 0;
if (prices.length <= 1) return 0;
int min = prices[0];
for (int i = 0; i < prices.length; i++) {
min = Math.min(min, prices[i]);
ret = Math.max(ret, prices[i] - min);
}
return ret;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment