mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-22 05:21:49 +03:00
feat: add Leetcode problem 119 (#997)
* added 119 * added 119.c Co-authored-by: David Leal <halfpacho@gmail.com>
This commit is contained in:
parent
8fa62620c2
commit
0cd4f6b691
@ -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
22
leetcode/src/119.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user