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]


public class Solution {
    public List<Integer> getRow(int k) {
        Integer[] arr = new Integer[k + 1];
        Arrays.fill(arr, 0);
        arr[0] = 1;
       
        for (int i = 1; i <= k; i++)
            for (int j = i; j > 0; j--)
                arr[j] = arr[j] + arr[j - 1];
       
        return Arrays.asList(arr);
    }
}

Post a Comment

0Comments
Post a Comment (0)

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

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