Last active
July 6, 2020 13:54
-
-
Save treyhuffine/4c4550e9de0017eb7253691fe66bc8c7 to your computer and use it in GitHub Desktop.
This file contains 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 maxProfit = 0; | |
for (let buyDay = 0; buyDay < prices.length; buyDay++) { | |
const buyPrice = prices[buyDay]; | |
for (let sellDay = buyDay + 1; sellDay < prices.length; sellDay++) { | |
const sellPrice = prices[sellDay]; | |
const currentProfit = sellPrice - buyPrice; | |
maxProfit = Math.max(maxProfit, currentProfit); | |
} | |
} | |
return maxProfit; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment