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

杨辉三角(一)

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

相关推荐

卖挂面鸡蛋不锈钢盆:top2 就发面试的年代已经一去不复发了
投递快手等公司10个岗位
点赞 评论 收藏
分享
爱读书的放鸽子能手很...:刷个两端实习,冲春招,流水线什么时候不能去
我的秋招日记
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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