You are viewing a single comment's thread. Return to all comments →
A scala solution: using the following property of Pascal's Triangle:
each row would be the sum of the previous row with 2 different 0-paddings (1) at the beginning (2) at the end, for example
object Solution { def pascal(n: Int):Array[Int] = n match { case 0 => Array(1) case _ => (0+:pascal(n-1), pascal(n-1):+0).zipped.map{_+_} } def main(args: Array[String]) { (0 until scala.io.StdIn.readInt).map(pascal).foreach(row => println(row.mkString(" "))) } }
Seems like cookies are disabled on this browser, please enable them to open this website
Pascal's Triangle
You are viewing a single comment's thread. Return to all comments →
A scala solution: using the following property of Pascal's Triangle:
each row would be the sum of the previous row with 2 different 0-paddings (1) at the beginning (2) at the end, for example