# [LeetCode],Pascal's Triangle, 解题报告

## 题目

Given numRows, generate the first numRows of Pascal's triangle.
For example, given numRows = 5,
Return

## AC代码

import java.util.*;

public class PascalTriangle {
public static ArrayList<ArrayList<Integer>> generate(int numRows) {
ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
if (numRows < 1) {
return result;
}
ArrayList<Integer> start = new ArrayList<Integer>();

for (int i = 1; i < numRows; i ++) {
ArrayList<Integer> pre = result.get(i - 1);
ArrayList<Integer> cur = new ArrayList<Integer>();

for (int j = 1; j < i; j ++) {
int tmp = pre.get(j - 1) + pre.get(j);
}

}

return result;
}

public static void main(String args[]) {
int n;
ArrayList<ArrayList<Integer>> list;
Scanner cin = new Scanner(System.in);

while (cin.hasNext()) {
n = cin.nextInt();
list = generate(n);

for (int i = 0; i < list.size(); i ++) {
for (int j = 0; j < list.get(i).size(); j ++) {
System.out.printf("%d ", list.get(i).get(j));
}
System.out.println();
}
}

cin.close();
}
}


• 本文已收录于以下专栏：

## 【LeetCode】Pascal's Triangle & II 解题报告

• ljiabin
• 2014年10月20日 17:45
• 3060

## 【leetcode】Pascal's Triangle[java]

public class Solution { public List> generate(int numRows) { //打印前n行的list //由上一个list产...

## [leetcode]Pascal's Triangle II (杨辉三角形求输出第k行的值)

Pascal’s Triangle II Given an index k, return the kth row of the Pascal’s triangle.For example, gi...

## LeetCode Pascal's Triangle II

Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1...

举报原因： 您举报文章：[LeetCode],Pascal's Triangle, 解题报告 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)