You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
508 B

package class30;
import java.util.ArrayList;
import java.util.List;
public class Problem_0118_PascalTriangle {
public static List<List<Integer>> generate(int numRows) {
List<List<Integer>> ans = new ArrayList<>();
for (int i = 0; i < numRows; i++) {
ans.add(new ArrayList<>());
ans.get(i).add(1);
}
for (int i = 1; i < numRows; i++) {
for (int j = 1; j < i; j++) {
ans.get(i).add(ans.get(i - 1).get(j - 1) + ans.get(i - 1).get(j));
}
ans.get(i).add(1);
}
return ans;
}
}