Ruby O(n) oneliner solution


  • 0
    S
    def max_profit(prices)
        prices.each_cons(2).map { |a,b| b - a }.select { |v| v > 0 }.reduce(:+) || 0
    end
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.