Created
January 30, 2018 08:55
-
-
Save clarkdo/00162c2d13923a8353cbfc19a53a7d70 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
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