LeetCode – Pascal’s Triangle (Java)
Given numRows, generate the first numRows of Pascal’s triangle. For example, given numRows = 5, the result should be: [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] Java Solution public ArrayList<ArrayList<Integer>> generate(int numRows) { ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>(); if (numRows <= 0) return result; ArrayList<Integer> pre = new ArrayList<Integer>(); pre.add(1); result.add(pre); for (int … Read more