Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fa2a8a7

Browse files
Merge pull request youngyangyang04#1673 from askaldk/master
update 455.分發餅乾 C語言
2 parents d3d3b3d + 2772fd4 commit fa2a8a7

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎problems/0455.分发饼干.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ function findContentChildren(g: number[], s: number[]): number {
274274
### C
275275

276276
```c
277+
///小餅乾先餵飽小胃口的
277278
int cmp(int* a, int* b) {
278279
return *a - *b;
279280
}
@@ -296,6 +297,33 @@ int findContentChildren(int* g, int gSize, int* s, int sSize){
296297
}
297298
```
298299
300+
```c
301+
///大餅乾先餵飽大胃口的
302+
int cmp(int* a, int* b) {
303+
return *a - *b;
304+
}
305+
306+
int findContentChildren(int* g, int gSize, int* s, int sSize){
307+
if(sSize == 0)
308+
return 0;
309+
310+
//将两个数组排序为升序
311+
qsort(g, gSize, sizeof(int), cmp);
312+
qsort(s, sSize, sizeof(int), cmp);
313+
314+
int count = 0;
315+
int start = sSize - 1;
316+
317+
for(int i = gSize - 1; i >= 0; i--) {
318+
if(start >= 0 && s[start] >= g[i] ) {
319+
start--;
320+
count++;
321+
}
322+
}
323+
return count;
324+
}
325+
```
326+
299327
### Scala
300328

301329
```scala

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /