Skip to content

Instantly share code, notes, and snippets.

@treyhuffine
Created July 4, 2020 02:50
Show Gist options
  • Save treyhuffine/88501ea5b74c812ed2d3e77de79f07f1 to your computer and use it in GitHub Desktop.
Save treyhuffine/88501ea5b74c812ed2d3e77de79f07f1 to your computer and use it in GitHub Desktop.
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