zoukankan      html  css  js  c++  java
  • Java实现 LeetCode 118 杨辉三角

    118. 杨辉三角

    给定一个非负整数 numRows,生成杨辉三角的前 numRows 行。

    在这里插入图片描述

    在杨辉三角中,每个数是它左上方和右上方的数的和。

    示例:

    输入: 5
    输出:

    [
         [1],
        [1,1],
       [1,2,1],
      [1,3,3,1],
     [1,4,6,4,1]
    ]
    
    class Solution {
        public List<List<Integer>> generate(int numRows) {
             int[][] arry = new int[numRows][numRows];
            List<List<Integer>> list = new ArrayList<List<Integer>>();
    	List<Integer> list1 = null;
            for (int i = 0; i < numRows; i++) {
    	    arry[i][0] = 1;
                list1 = new ArrayList<Integer>();
                list1.add(arry[i][0]);
                for (int j = 1; j <= i; j++) {
                    arry[i][j] = arry[i-1][j-1] +arry[i-1][j];
                    list1.add(arry[i][j]);
    		    }
                list.add(list1);
    	    }
            return list;
        }
    }
    
  • 相关阅读:
    第三次冲刺
    第二次冲刺
    第一次冲刺
    团队学习
    git and github
    还不够格的程序员
    CF1602F. Difficult Mountain
    线性基
    欧拉回路学习笔记
    莫比乌斯反演-学习笔记
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13075530.html
Copyright © 2011-2022 走看看