author: Blankj blog : http://blankj.com time : 2017/10/11 desc :
| 14 | * </pre> |
| 15 | */ |
| 16 | public class Solution { |
| 17 | public List<List<Integer>> generate(int numRows) { |
| 18 | if (numRows == 0) return Collections.emptyList(); |
| 19 | List<List<Integer>> list = new ArrayList<>(); |
| 20 | for (int i = 0; i < numRows; ++i) { |
| 21 | List<Integer> sub = new ArrayList<>(); |
| 22 | for (int j = 0; j <= i; ++j) { |
| 23 | if (j == 0 || j == i) { |
| 24 | sub.add(1); |
| 25 | } else { |
| 26 | List<Integer> upSub = list.get(i - 1); |
| 27 | sub.add(upSub.get(j - 1) + upSub.get(j)); |
| 28 | } |
| 29 | } |
| 30 | list.add(sub); |
| 31 | } |
| 32 | return list; |
| 33 | } |
| 34 | |
| 35 | public static void main(String[] args) { |
| 36 | Solution solution = new Solution(); |
| 37 | System.out.println(solution.generate(5)); |
| 38 | } |
| 39 | } |
nothing calls this directly
no outgoing calls
no test coverage detected