AC Ruby version 56ms


  • 0
    H

    Neat and straightforward solution written by Ruby

    def generate(num_rows)
      return [] if num_rows <= 0
    
      1.upto(num_rows - 1).each_with_object([[1]]) do |i, acc|
        acc[i] = 0.upto(i).map do |j|
          j < 1 ? 1 : acc[i - 1][j - 1] + acc[i - 1][j].to_i
        end
      end
    end
    

Log in to reply
 

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