반응형
https://leetcode.com/problems/pascals-triangle-ii/
Pascal's Triangle II - LeetCode
Can you solve this real interview question? Pascal's Triangle II - 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: [https
leetcode.com
class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int> res(rowIndex + 1, 1);
for(int i=2; i<=rowIndex; i++) {
for(int j=i - 1; j>=1; j--)
res[j] = res[j - 1] + res[j];
}
return res;
}
};
반응형
'Algorithm' 카테고리의 다른 글
LeetCode 2050. Parallel Courses III (0) | 2023.10.18 |
---|---|
LeetCode 1361. Validate Binary Tree Nodes (0) | 2023.10.18 |
LeetCode 1269. Number of Ways to Stay in the Same Place After Some Steps (0) | 2023.10.15 |
LeetCode 1095. Find in Mountain Array (0) | 2023.10.12 |
LeetCode 720. Longest Word in Dictionary (0) | 2023.10.09 |