Sunday, October 8, 2017

119. Pascal's Triangle II



49.87 %
class Solution {
    public List<Integer> getRow(int rowIndex) {
        List<Integer> result = new ArrayList<>();
        if (rowIndex < 0) return result;
        for (int x = 0; x <= rowIndex; x++) {
            result.add(1);
            for (int y = x - 1; y > 0; y--) {
                result.set(y, result.get(y) + result.get(y - 1));
            }
        }
        return result;
       
    }
}

No comments:

Post a Comment