题解 | #杨辉三角(一)#
杨辉三角(一)
http://www.nowcoder.com/practice/4385fa1c390e49f69fcf77ecffee7164
import java.util.*;
public class Solution {
public int[][] generate (int num) {
// write code here
int[][] arr = new int[num][];
int i,j;
for(i=0;i<num;i++){
arr[i] = new int[i+1];
if(i==0)arr[0][0]=1;
else {
for(j=0;j<=i;j++){
int t1 = j-1<0?0:arr[i-1][j-1];
int t2 = j == i?0:arr[i-1][j];
arr[i][j]=t2+t1;
}
}
}
return arr;
}
}