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

Commitb429fbc

Browse files
Pascal's Triangle II
1 parentef1e581 commitb429fbc

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

‎EASY/src/easy/PascalsTriangleII.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
packageeasy;
2+
importjava.util.*;
3+
publicclassPascalsTriangleII {
4+
5+
publicList<Integer>getRow(introwIndex) {
6+
if(rowIndex <0)returnnewArrayList();
7+
List<List<Integer>>result =newArrayList();
8+
List<Integer>row =newArrayList();
9+
row.add(1);
10+
result.add(row);
11+
for(inti =1;i <=rowIndex;i++){
12+
List<Integer>newRow =newArrayList();
13+
newRow.add(1);
14+
List<Integer>lastRow =result.get(i-1);
15+
for(intj =1;j <lastRow.size();j++){
16+
newRow.add(lastRow.get(j-1) +lastRow.get(j));
17+
}
18+
newRow.add(1);
19+
result.add(newRow);
20+
}
21+
returnresult.get(result.size()-1);
22+
}
23+
24+
}

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
|125|[Valid Palindrome](https://leetcode.com/problems/valid-palindrome/)|[Solution](../../blob/master/EASY/src/easy/ValidPalindrome.java)| O(n)|O(1) | Easy| Two Pointers
3333
|122|[Best Time to Buy and Sell Stock II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/)|[Solution](../../blob/master/MEDIUM/src/medium/BestTimeToBuyAndSellStockII.java)| O(n)|O(1) | Medium | Greedy
3434
|121|[Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/)|[Solution](../../blob/master/EASY/src/easy/BestTimeToBuyAndSellStock.java)| O(n)|O(1) | Easy| DP
35+
|119|[Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii/)|[Solution](../../blob/master/EASY/src/easy/PascalsTriangleII.java)| O(n^2)|O(1)| Easy|
3536
|118|[Pascal's Triangle](https://leetcode.com/problems/pascals-triangle/)|[Solution](../../blob/master/EASY/src/easy/PascalsTriangle.java)| O(n^2)|O(1)| Easy|
3637
|117|[Populating Next Right Pointers in Each Node II](https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/)|[Solution](../../blob/master/HARD/src/hard/PopulatingNextRightPointersinEachNodeII.java)| O(n)|O(1) | Hard| BFS
3738
|116|[Populating Next Right Pointers in Each Node](https://leetcode.com/problems/populating-next-right-pointers-in-each-node/)|[Solution](../../blob/master/MEDIUM/src/medium/PopulatingNextRightPointersinEachNode.java)| O(n)|O(1) | Medium| BFS

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp