/ **
* numRows given a value, before generating Pascal triangle with numRows
* example given. 5 = numRows,
* return
* [↵ [1], ↵ [1,1], ↵ [1,2,1] , ↵ [1,3,3,1], ↵ [1,4,6,4,1] ↵]
* /
of java.util.ArrayList Import; / ** * numRows given a value, before generating Pascal triangle with numRows * example given. 5 = numRows, * return * [↵ [1], ↵ [1,1], ↵ [1,2,1], ↵ [1,3,3,1], ↵ [1,4,6,4,1] ↵] * / public class Main51 { public static void main (String [] args) { System.out.println (Main51.generate (. 5)); } public static the ArrayList <the ArrayList <Integer >> Generate (int numRows) { the ArrayList <the ArrayList <Integer List the ArrayList = new new >> <> (); the ArrayList <Integer> the ArrayList = new new Last <> (); IF (numRows == 0) { return List; } for (int I = 0; I <numRows; I ++) { ArrayList<Integer> array = new ArrayList<>(); if (i > 1) { last = list.get(i-1); } for (int j=0;j<=i;j++) { if (j==0 || j==i) { array.add(1); }else{ array.add(last.get(j-1)+last.get(j)); } } list.add(array); } return list; } }