Created
January 23, 2020 22:35
-
-
Save muxcmux/27159814ff7e3d6b6cf877362f8de440 to your computer and use it in GitHub Desktop.
wtf is the complexity for this shit?!
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
# @param {Integer[]} prices | |
# @return {Integer} | |
def max_profit(prices) | |
mp = 0 | |
prices.each_with_index do |price, i| | |
for n in (i + 1)..prices.count do | |
profit = prices[n].to_i - price | |
mp = profit if profit > mp | |
end | |
end | |
mp | |
end | |
puts max_profit([7,1,5,3,6,4]) | |
puts max_profit([7,6,4,3,1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment