feat: add Leetcode problem 119 (#997)

* added 119

* added 119.c

Co-authored-by: David Leal <halfpacho@gmail.com>
This commit is contained in:
Adhiraj 2022-10-29 05:17:45 +05:30 committed by GitHub
parent 8fa62620c2
commit 0cd4f6b691
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -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 |

22
leetcode/src/119.c Normal file
View File

@ -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;
}