题解 | #杨辉三角(一)#

杨辉三角(一)

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;
    }
}
全部评论

相关推荐

06-11 17:39
门头沟学院 Java
小呆呆的大鼻涕:卧槽,用户彻底怒了
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-07 13:15
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务