304 North Cardinal St.
Dorchester Center, MA 02124

# Pascal’s Triangle II LeetCode Solution – Queslers

## Problem – Pascal’s Triangle II LeetCode Solution

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:

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]``````

Constraints:

• `0 <= rowIndex <= 33`

### Pascal’s Triangle II LeetCode Solution in Python

``````class Solution(object):
def getRow(self, rowIndex):
"""
:type rowIndex: int
:rtype: List[int]
"""
row = [1]
for _ in range(rowIndex):
row = [x + y for x, y in zip([0]+row, row+[0])]
return row
``````

### Pascal’s Triangle II LeetCode Solution in Java

``````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);
}
}
``````

### Pascal’s Triangle II LeetCode Solution in C++

``````class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int> vi(rowIndex + 1);
vi[0] = 1;
for (int i = 0; i <= rowIndex ; ++i)
{
for (int j = i; j > 0; --j)
{
vi[j] = vi[j] + vi[j-1];
}
}
return vi;
}
};
``````
##### Pascal’s Triangle II LeetCode Solution Review:

In our experience, we suggest you solve this Pascal’s Triangle II LeetCode Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Pascal’s Triangle II LeetCode Solution

Find on LeetCode

##### Conclusion:

I hope this Pascal’s Triangle II LeetCode Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions