Skip to content

Instantly share code, notes, and snippets.

@clarkdo
Created January 30, 2018 08:55
Show Gist options
  • Save clarkdo/00162c2d13923a8353cbfc19a53a7d70 to your computer and use it in GitHub Desktop.
Save clarkdo/00162c2d13923a8353cbfc19a53a7d70 to your computer and use it in GitHub Desktop.
class Solution {
public int solution(int[] A) {
int len = A.length;
if (len == 0) return 0;
int min = A[0];
int profits = 0;
for (int i = 1; i < len; i++) {
int price = A[i];
if (price < min) {
min = price;
} else {
int diff = price - min;
if (diff > profits) {
profits = diff;
}
}
}
return profits;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment