mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
添加 0455.分发饼干.md C语言版本
This commit is contained in:
@ -217,6 +217,29 @@ var findContentChildren = function(g, s) {
|
||||
|
||||
```
|
||||
|
||||
C:
|
||||
```c
|
||||
int cmp(int* a, int* b) {
|
||||
return *a - *b;
|
||||
}
|
||||
|
||||
int findContentChildren(int* g, int gSize, int* s, int sSize){
|
||||
if(sSize == 0)
|
||||
return 0;
|
||||
|
||||
//将两个数组排序为升序
|
||||
qsort(g, gSize, sizeof(int), cmp);
|
||||
qsort(s, sSize, sizeof(int), cmp);
|
||||
|
||||
int numFedChildren = 0;
|
||||
int i = 0;
|
||||
for(i = 0; i < sSize; ++i) {
|
||||
if(numFedChildren < gSize && g[numFedChildren] <= s[i])
|
||||
numFedChildren++;
|
||||
}
|
||||
return numFedChildren;
|
||||
}
|
||||
```
|
||||
|
||||
-----------------------
|
||||
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
|
||||
|
Reference in New Issue
Block a user