<?php
class Solution {
/**
* @param Integer $numRows
* @return Integer[][]
*/
function generate($numRows) {
if($numRows == 1){
return [[1]];
}
$arr = [[1],[1,1]];
if($numRows == 2){
return $arr;
}
for($i=3;$i<=$numRows;$i++){
$pre = $arr[$i-2];
$temp = [1];
for($j=1;$j<$i-1;$j++){
$sum = $pre[$j] + $pre[$j-1];
$temp[$j] = $sum;
}
$temp[] = 1;
$arr[] = $temp;
}
return $arr;
}
}
image.png
网友评论