Last active
September 13, 2018 02:45
-
-
Save BryanJin/276cd820f931e0ed904368333adaa3ae 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 int maxProfit(int[] prices) { | |
int maxProfit = 0; | |
int minPrice = Integer.MAX_VALUE; | |
for (int currPrice : prices) { | |
if(minPrice > currPrice) | |
minPrice = currPrice; | |
if (currPrice - minPrice > maxProfit) | |
maxProfit = currPrice - minPrice; | |
} | |
return maxProfit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment