mirror of https://github.com/TheAlgorithms/C
feat: add LeetCode problem 118 (#996)
* added 118 to list * added 118.c
This commit is contained in:
parent
52d3b3ee4d
commit
82ca460a9c
|
@ -37,6 +37,7 @@ LeetCode
|
|||
|109|[Convert Sorted List to Binary Search Tree](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/) | [C](./src/109.c)|Medium|
|
||||
|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|
|
||||
|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|
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* Return an array of arrays of size *returnSize.
|
||||
* The sizes of the arrays are returned as *returnColumnSizes array.
|
||||
* Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
|
||||
*/
|
||||
int** generate(int numRows, int* returnSize, int** returnColumnSizes){
|
||||
*returnSize = numRows;
|
||||
int **ans = (int**)malloc(numRows*sizeof(int*));
|
||||
*returnColumnSizes = (int*)malloc(numRows*sizeof(int));
|
||||
|
||||
for (int i=0; i<numRows; i++) {
|
||||
(*returnColumnSizes)[i] = i + 1;
|
||||
ans[i] = (int*)malloc((i+1)*sizeof(int));
|
||||
}
|
||||
|
||||
ans[0][0] = 1;
|
||||
|
||||
for (int i=1; i<numRows; i++) {
|
||||
ans[i][0] = 1;
|
||||
for (int j=1; j<i; j++) {
|
||||
ans[i][j] = ans[i-1][j-1] + ans[i-1][j];
|
||||
}
|
||||
ans[i][i] = 1;
|
||||
}
|
||||
return ans;
|
||||
}
|
Loading…
Reference in New Issue