diff --git a/leetcode/README.md b/leetcode/README.md index 30a5197a..8e9fe6a6 100644 --- a/leetcode/README.md +++ b/leetcode/README.md @@ -37,6 +37,7 @@ | 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree/) | [C](./src/110.c) | Easy | | 112 | [Path Sum](https://leetcode.com/problems/path-sum/) | [C](./src/112.c) | Easy | | 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle/) | [C](./src/118.c) | Easy | +| 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii/) | [C](./src/119.c) | Easy | | 121 | [Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/) | [C](./src/121.c) | Easy | | 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome/) | [C](./src/125.c) | Easy | | 136 | [Single Number](https://leetcode.com/problems/single-number/) | [C](./src/136.c) | Easy | diff --git a/leetcode/src/119.c b/leetcode/src/119.c new file mode 100644 index 00000000..a4b6f7a9 --- /dev/null +++ b/leetcode/src/119.c @@ -0,0 +1,22 @@ +/** + * Note: The returned array must be malloced, assume caller calls free(). + */ +int* getRow(int rowIndex, int* returnSize){ + int colIndex = rowIndex + 1; + int* ans = (int*) malloc(sizeof(int) * colIndex); + for (int i = 0; i < colIndex; i++) + { + ans[i] = 1; + } + *returnSize = colIndex; + + for (int r = 2; r <= rowIndex; r++) + { + for (int c = r - 1; c > 0; c--) + { + ans[c] = ans[c] + ans[c-1]; + } + } + + return ans; +}