One line of ruby


  • 0
    P
      def max_profit(prices)
        prices.size > 1 ? prices.each_cons(2).map { |(a,b)| [b - a, 0].max }.reduce(:+) : 0
      end

Log in to reply
 

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