leetcode-Pascal's Triangle II

和Pascal's Triangle I差不多的思想。

public class Solution {
    public List getRow(int rowIndex) {
         ArrayList results = new ArrayList();
		    results.add(1);
		    for (int i = 1; i <= rowIndex; ++i) {
		      int temp = 1;
		      for (int j = 1; j < i; ++j) {
		        int innerTemp = results.get(j);
		        results.set(j, temp + results.get(j));
		        temp = innerTemp;
		      }
		      System.out.println(results);
		      results.add(1);
		    }
		    return results;
    }
}


你可能感兴趣的:(leetcode)