Leetcode 118 Pascal's triangle Solution in java | Hindi Coding Community

0

 

Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal's triangle.


Example 1:


Input: rowIndex = 3

Output: [1,3,3,1]


class Solution {
public:
    vector<int> getRow(int rowIndex) {
        vector<int> ansArray(rowIndex+1,0);
        ansArray[0] = 1;
       
        for (int i = 1; i <= rowIndex; i++)
            for (int j = i; j > 0; j--)
                ansArray[j] = ansArray[j] + ansArray[j - 1];
       
        return ansArray;
    }
};

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !