Created
July 4, 2020 02:50
-
-
Save treyhuffine/88501ea5b74c812ed2d3e77de79f07f1 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
const getMaxProfit = (prices) => { | |
let minPrice = prices[0]; | |
let maxProft = 0; | |
for (const price of prices) { | |
const currentProfit = price - minPrice; | |
minPrice = Math.min(minPrice, price); | |
maxProft = Math.max(maxProft, price - minPrice); | |
} | |
return maxProft; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment