题目链接:
链接
题目描述:
思路:
直接找规律,按照数学的思路来
每一行的列最大索引 <= 行索引
实现代码:
class Solution {public List<List<Integer>> generate(int numRows) {List<List<Integer>> ans = new ArrayList<List<Integer>>();for(int i = 0; i < numRows ; i++){List<Integer> tmp = new ArrayList<Integer>();for(int j = 0; j <= i; j++){ if(j == 0 || j == i){ //首尾都是1tmp.add(1);}else{//中间就是上一行相邻两个元素相加tmp.add(ans.get(i-1).get(j-1) + ans.get(i-1).get(j));}}ans.add(tmp);}return ans;}
}