You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 6648ba5
Browse filesBrowse the repository at this point in the historyBrowse files
假设你是一位很棒的家长,想要给你的孩子们一些小饼干。但是,每个孩子最多只能给一块饼干。对每个孩子 i ,都有一个胃口值 gi ,这是能让孩子们满足胃口的饼干的最小尺寸;并且每块饼干 j ,都有一个尺寸 sj 。如果 sj >= gi ,我们可以将这个饼干 j 分配给孩子 i ,这个孩子会得到满足。你的目标是尽可能满足越多数量的孩子,并输出这个最大数值。
1244
+
1245
+
**注意:**
1246
+
1247
+
你可以假设胃口值为正。
1248
+
一个小朋友最多只能拥有一块饼干。
1249
+
1250
+
**示例 1:**
1251
+
1252
+
```
1253
+
输入: [1,2,3], [1,1]
1254
+
1255
+
输出: 1
1256
+
1257
+
解释:
1258
+
你有三个孩子和两块小饼干,3个孩子的胃口值分别是:1,2,3。
1259
+
虽然你有两块小饼干,由于他们的尺寸都是1,你只能让胃口值是1的孩子满足。
1260
+
所以你应该输出1。
1261
+
```
1262
+
1263
+
**示例 2:**
1264
+
1265
+
```
1266
+
输入: [1,2], [1,2,3]
1233
1267
1268
+
输出: 2
1234
1269
1270
+
解释:
1271
+
你有两个孩子和三块小饼干,2个孩子的胃口值分别是1,2。
1272
+
你拥有的饼干数量和尺寸都足以让所有孩子满足。
1273
+
所以你应该输出2.
1274
+
```
1275
+
1276
+
1277
+
1278
+
```java
1279
+
publicclassSolution {
1280
+
1281
+
publicintfindContentChildren(int[] g, int[] s) {
1282
+
int res =0;
1283
+
Arrays.sort(g);
1284
+
Arrays.sort(s);
1285
+
1286
+
for (int i = g.length -1; i >=0; i--) {
1287
+
for (int j = s.length -1; j >=0; j--) {
1288
+
if(s[j] >= g[i]){
1289
+
res ++;
1290
+
s[j] =0;
1291
+
break;
1292
+
}
1293
+
}
1294
+
}
1295
+
1296
+
return res;
1297
+
}
1298
+
1299
+
1300
+
publicstaticvoidmain(String[] args) {
1301
+
int res =newSolution().findContentChildren(newint[]{1,2,3}, newint[]{3});
0 commit comments