/**
 *	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?
 *
 *	Author: matao
 *
 */

import java.util.List;
import java.util.ArrayList;

public class PascalTriangleII {
	public static List<Integer> getRow1(int rowIndex) {
        if(rowIndex < 0) {
        	return null;
        }
        List<List<Integer>> total = new ArrayList<List<Integer>>();
        for (int i = 0; i <= rowIndex; i++) {
        	List<Integer> item = new ArrayList<Integer>();
        	for (int j = 0; j <= i; j++) {
        		if(j == 0 || j == i) {
        			item.add(1);
        		} else {
        			item.add(total.get(i-1).get(j-1) + total.get(i-1).get(j));
        		}
        	}
        	total.add(item);
        }
        return total.get(rowIndex);
    }

    public static List<Integer> getRow2(int rowIndex) {
    	
    }

    public static void main(String[] args) {
    	System.out.println(getRow1(3));
    	System.out.println(getRow2(3));
    }
}
@@ -938,16 +938,555 @@
  %7B%0A    %09
+if (rowIndex %3C 0) %7B%0A    %09%09return null;%0A    %09%7D%0A    %09List%3CInteger%3E result = new ArrayList%3CInteger%3E();%0A    %09if (rowIndex == 0) %7B%0A    %09%09result.add(1);%0A    %09%7D%0A%0A    %09for (int i = 1; i %3C= rowIndex; i++) %7B%0A    %09%09List%3CInteger%3E tmp = new ArrayList%3CInteger%3E();%0A    %09%09for (int j = 0; j %3C= i; j++) %7B%0A    %09%09%09tmp.add(-1);%0A    %09%09%7D%0A%0A    %09%09for (int j = 0; j %3C= i; j++) %7B%0A    %09%09%09if (j == 0 %7C%7C j == i) %7B%0A    %09%09%09%09tmp.set(j, 1);%0A    %09%09%09%7D else %7B%0A    %09%09%09%09tmp.set(j, result.get(j) + result.get(j-1));%0A    %09%09%09%7D%0A    %09%09%7D%0A    %09%09result = tmp;%0A    %09%7D%0A    %09return result;
 %0A    %7D%0A%0A

optimize Pascal Triangle II solution