> For the complete documentation index, see [llms.txt](https://blog.yushunchen.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://blog.yushunchen.com/algo/array/pascals-triangle-ii.md).

# Pascal's Triangle II

{% embed url="<https://leetcode.com/problems/pascals-triangle-ii/>" %}

## Solution 1

```go
func getRow(rowIndex int) []int {
    res := make([]int, rowIndex + 1)
    res[0] = 1
    for i := 1; i < rowIndex+1; i++ {
        res[i] = res[i-1] * (rowIndex-i+1) / i
    }
    return res
}
```

$$
{n\choose{m}}={n\choose{m-1}} \times \frac{n-m+1}{m}
$$

```java
class Solution {
    public List<Integer> getRow(int rowIndex) {
        List<Integer> ans = new ArrayList<>();
        ans.add(1);
        long curElement = 1;
        for (int i = 1; i <= rowIndex; i++) {
            curElement = curElement * (rowIndex-i+1) / i;
            ans.add((int)curElement);
        }
        return ans;
    }
}
```
