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

Appearance settings

Latest commit

 

History

History
History
28 lines (27 loc) · 782 Bytes

File metadata and controls

28 lines (27 loc) · 782 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
Author: Annie Kim, anniekim.pku@gmail.com
Date: Apr 16, 2013
Problem: Pascal's Triangle II
Difficulty: Easy
Source: http://leetcode.com/onlinejudge#question_119
Notes:
Given an index k, return the kth row of the Pascal's triangle.
For example, given k = 3,
Return [1,3,3,1].
Note:
Could you optimize your algorithm to use only O(k) extra space?
Solution: from back to forth...
*/
public class Solution {
public List<Integer> getRow(int rowIndex) {
List<Integer> res = new ArrayList<Integer>();
res.add(1);
for (int i = 1; i <= rowIndex; ++i) {
for (int j = i - 1; j >= 1; --j) {
res.set(j,res.get(j) + res.get(j-1));
}
res.add(1);
}
return res;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.