[LeetCode]Pascal's Triangle II

2015-01-27 05:59:35 · 作者: · 浏览: 3

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?


public class Solution {
    public List
  
    getRow(int rowIndex) {
    	List
   
     list = new ArrayList<>(); for(int i=0;i
    
     0;j--){ int element = list.get(j)+list.get(j-1); list.set(j, element); } list.add(1); } return list; } }