Skip to content

Commit db6d865

Browse files
author
lightmen
committed
add assign-cookies.c at Tue Mar 21 00:46:08 CST 2017
1 parent ef37a27 commit db6d865

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

c/greedy/assign-cookies.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
int cmp(const void *a, const void *b)
2+
{
3+
return *(int *)a - *(int *)b;
4+
}
5+
6+
int findContentChildren(int* g, int gSize, int* s, int sSize) {
7+
int i = gSize - 1;
8+
int j = sSize - 1;
9+
int ret = 0;
10+
11+
qsort(g, gSize, sizeof(int), cmp);
12+
qsort(s, sSize, sizeof(int), cmp);
13+
14+
while(i >= 0 && j >= 0){
15+
if(s[j] >= g[i]){
16+
j--;
17+
ret++;
18+
}
19+
i--;
20+
}
21+
22+
return ret;
23+
}

0 commit comments

Comments
 (0)