Hi, this is Shunchi!

  • Home

  • Tags0

  • Archives267

  • Categories0

  • Curricula

  • DSA

  • LeetCode_Notes

  • Interviews

  • General

  • Resume

119. Pascal's Triangle II

Posted on 2020-04-04 | Edited on 2021-01-22

https://leetcode.com/problems/pascals-triangle-ii/


Recursion –> top down DP memoization

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
// int[][] memo;
private int getNum(int row,int col){
if(row==0||col==0||col==row) return 1;
// if(memo[row][col]>0) return memo[row][col];
return memo[row][col]=getNum(row-1,col-1)+getNum(row-1,col);
}
public List<Integer> getRow(int rowIndex) {
List<Integer> ans=new ArrayList<>();
// memo = new int[rowIndex+1][rowIndex+1];
for(int i=0;i<=rowIndex;i++){
ans.add(getNum(rowIndex,i));
}
return ans;
}
}

<1…243244245…267>
ShunchiZhou

ShunchiZhou

267 posts
RSS
GitHub E-Mail Gitbook Linkedin
© 2024 ShunchiZhou
Powered by Hexo v5.4.0
|
0%