Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit06c2640

Browse files
committed
Update 0119-pascals-triangle-ii.java
1 parent372e1c8 commit06c2640

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎java/0119-pascals-triangle-ii.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,24 @@ public int value(int row, int col, int[][] dp) {
1717
dp[row][col] =value(row -1,col -1,dp) +value(row -1,col,dp);
1818
returndp[row][col];
1919
}
20+
21+
/** Iterative approach to solving the problem - follows Neetcode's solution in Python
22+
* O(n) time complexity
23+
* */
24+
publicList<Integer>getRow(introwIndex) {
25+
List<Integer>res =newArrayList<>(rowIndex +1);
26+
for (inti =0;i <rowIndex +1;i++) {
27+
res.add(1);
28+
}
29+
30+
for (inti =2;i <rowIndex +1;i++) {
31+
for (intj =i -1;j >0;j--) {
32+
res.set(j,res.get(j) +res.get(j -1));
33+
}
34+
}
35+
returnres;
36+
}
37+
38+
2039
}
2140
//todo: add bottom up approach

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp