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

In Pascal's triangle, each number is the sum of the two numbers directly above it as shown:

&nbsp;
Example 1:
Input: rowIndex = 3
Output: [1,3,3,1]
Example 2:
Input: rowIndex = 0
Output: [1]
Example 3:
Input: rowIndex = 1
Output: [1,1]

&nbsp;
Constraints:


	0 &lt;= rowIndex &lt;= 33


&nbsp;
Follow up: Could you optimize your algorithm to use only O(rowIndex) extra space?

class Solution:
    def getRow(self, rowIndex: int) -> List[int]:
        # base case
        # we know that there exist two base case one which is for zero input
        # One when we have to exit our recursive loop 
        if rowIndex == 0:
            return [1]
        if rowIndex == 1:
            return [1,1]
        #recurance relation or prev call
        prev_prob = self.getRow(rowIndex-1)
        # post processing on data 
        # if someone has given us prev_Row what operation we can perform to get current_Row
        return [1]+[prev_prob[i]+prev_prob[i-1] for i in range(1,len(prev_prob))]+[1]
class Solution {
    public List<Integer> getRow(int rowIndex) {
        List<List<Integer>> out = new ArrayList<>();
        for(int i = 0; i<=rowIndex; i++){
            List<Integer>in = new ArrayList<>(i+1);
            for(int j = 0 ; j<= i; j++){
                if(j == 0 || j == i){
                    in.add(1);
                }
                else{
                    in.add(out.get(i-1).get(j-1) + out.get(i-1).get(j));
                }
                
            }
            out.add(in);
        }
        return out.get(rowIndex);
    }
}
class Solution {
public:
    vector<int> getRow(int rowIndex) {
        vector<int> ans(rowIndex+1,0);
        ans[0]=1;
        for(int i=1;i<rowIndex+1;i++){
            for(int j=i;j>=1;j--){
                ans[j]=ans[j]+ans[j-1];
            }
        }
        return ans;
    }
};
var getRow = function(rowIndex) {
    const triangle = [];

    for (let i = 0; i <= rowIndex; i++) {
        const rowValue = [];

        for (let j = 0; j < i + 1; j++) {
             if (j === 0 || j === i) {
                 rowValue[j] = 1;
             } else {
                 rowValue[j] = triangle[i - 1][j - 1] + triangle[i - 1][j];
             }
        }
        triangle.push(rowValue)
    }

    return triangle[rowIndex];
};
Pascal's Triangle II