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

Commitef1e581

Browse files
Pascal's triangle
1 parentdf480fc commitef1e581

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

‎EASY/src/easy/PascalsTriangle.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
packageeasy;
2+
importjava.util.*;
3+
4+
publicclassPascalsTriangle {
5+
6+
publicstaticList<List<Integer>>generate(intnumRows) {
7+
List<List<Integer>>result =newArrayList();
8+
if(numRows <1)returnresult;
9+
List<Integer>row =newArrayList();
10+
row.add(1);
11+
result.add(row);
12+
for(inti =1;i <numRows;i++){
13+
List<Integer>newRow =newArrayList();
14+
newRow.add(1);
15+
List<Integer>lastRow =result.get(i-1);
16+
for(intj =1;j <lastRow.size();j++){
17+
newRow.add(lastRow.get(j-1) +lastRow.get(j));
18+
}
19+
newRow.add(1);
20+
result.add(newRow);
21+
}
22+
returnresult;
23+
}
24+
25+
publicstaticvoidmain(String...strings){
26+
intnumRows =2;
27+
generate(numRows);
28+
}
29+
}

‎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+
|118|[Pascal's Triangle](https://leetcode.com/problems/pascals-triangle/)|[Solution](../../blob/master/EASY/src/easy/PascalsTriangle.java)| O(n^2)|O(1)| Easy|
3536
|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
3637
|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
3738
|111|[Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree/)|[Solution](../../blob/master/EASY/src/easy/MinimumDepthofBinaryTree.java)| O(n)|O(1)~O(h) | Easy| BFS, DFS

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp