• Leetcode: Pascal's Triangle


    Given numRows, generate the first numRows of Pascal's triangle.
    
    For example, given numRows = 5,
    Return
    
    [
         [1],
        [1,1],
       [1,2,1],
      [1,3,3,1],
     [1,4,6,4,1]
    ]
     1 public class Solution {
     2     public ArrayList<ArrayList<Integer>> generate(int numRows) {
     3         ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
     4         List<Integer> item;
     5         if (numRows <= 0) return result;
     6         for (int i=0; i<numRows; i++) {
     7             item = new ArrayList<Integer>();
     8             for (int j=0; j<=i; j++) {
     9                 if (j==0 || j==i) item.add(1);
    10                 else {
    11                     List<Integer> prev = result.get(i-1);
    12                     item.add(prev.get(j-1) + prev.get(j));
    13                 }
    14             }
    15             result.add(new ArrayList<Integer>(item));
    16         }
    17         return result;
    18     }
    19 }
  • 相关阅读:
    Splash wait() 方法
    Splash go() 方法
    Splash 对象方法
    短信接口文档
    WMS开发环境
    Eureka
    pom.xml settings.xml
    Druid
    EAI并发
    重启WMS服务
  • 原文地址:https://www.cnblogs.com/EdwardLiu/p/3756296.html
Copyright © 2020-2023  润新知