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

Commite7101d1

Browse files
author
applewjg
committed
Pascal'sTriangleII
Change-Id: Ia0c002759fe33aec45490fd8adcd3cb6f6faaba8
1 parentac27b27 commite7101d1

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎Pascal'sTriangleII.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
Author: Annie Kim, anniekim.pku@gmail.com
3+
Date: Apr 16, 2013
4+
Problem: Pascal's Triangle II
5+
Difficulty: Easy
6+
Source: http://leetcode.com/onlinejudge#question_119
7+
Notes:
8+
Given an index k, return the kth row of the Pascal's triangle.
9+
For example, given k = 3,
10+
Return [1,3,3,1].
11+
Note:
12+
Could you optimize your algorithm to use only O(k) extra space?
13+
14+
Solution: from back to forth...
15+
*/
16+
publicclassSolution {
17+
publicList<Integer>getRow(introwIndex) {
18+
List<Integer>res =newArrayList<Integer>();
19+
res.add(1);
20+
for (inti =1;i <=rowIndex; ++i) {
21+
for (intj =i -1;j >=1; --j) {
22+
res.set(j,res.get(j) +res.get(j-1));
23+
}
24+
res.add(1);
25+
}
26+
returnres;
27+
}
28+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp