标签:class lse else win code pascal lis asc int
1 class Solution { 2 List<Integer> res = new ArrayList<>(); 3 public List<Integer> getRow(int rowIndex) { 4 helper(1, rowIndex + 1, new ArrayList<>(), null); 5 return res; 6 7 } 8 9 public void helper(int num, int total, List<Integer> list, List<Integer> prev) { 10 if(num > total) return; 11 12 for(int i = 1; i <= num; i++) { 13 if(num == 1 || num == 2) { 14 list.add(1); 15 }else { 16 if(i == 1 || i == num) { 17 list.add(1); 18 }else { 19 list.add(prev.get(i-2) + prev.get(i-1));//注意是i-2 循环用的是1开始 20 } 21 } 22 } 23 if(num == total) res = list; 24 helper(num+1, total, new ArrayList<>(), list); 25 } 26 }
标签:class lse else win code pascal lis asc int
原文地址:https://www.cnblogs.com/goPanama/p/9689312.html