This commit is contained in:
youngyangyang04
2021-11-11 01:34:12 +08:00
parent 124924dee2
commit a0de1660f6
10 changed files with 124 additions and 115 deletions

View File

@@ -7,7 +7,7 @@
<p align="center"><strong>欢迎大家<a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
## 455.分发饼干
# 455.分发饼干
[力扣题目链接](https://leetcode-cn.com/problems/assign-cookies/)
@@ -16,20 +16,14 @@
对每个孩子 i都有一个胃口值 g[i],这是能让孩子们满足胃口的饼干的最小尺寸;并且每块饼干 j都有一个尺寸 s[j] 。如果 s[j] >= g[i],我们可以将这个饼干 j 分配给孩子 i ,这个孩子会得到满足。你的目标是尽可能满足越多数量的孩子,并输出这个最大数值。
示例 1:
输入: g = [1,2,3], s = [1,1]
输出: 1
解释:
你有三个孩子和两块小饼干3个孩子的胃口值分别是1,2,3。
虽然你有两块小饼干由于他们的尺寸都是1你只能让胃口值是1的孩子满足。
所以你应该输出1。
* 输入: g = [1,2,3], s = [1,1]
* 输出: 1
解释:你有三个孩子和两块小饼干3个孩子的胃口值分别是1,2,3。虽然你有两块小饼干由于他们的尺寸都是1你只能让胃口值是1的孩子满足。所以你应该输出1。
示例 2:
输入: g = [1,2], s = [1,2,3]
输出: 2
解释:
你有两个孩子和三块小饼干2个孩子的胃口值分别是1,2。
你拥有的饼干数量和尺寸都足以让所有孩子满足。
所以你应该输出2.
* 输入: g = [1,2], s = [1,2,3]
* 输出: 2
* 解释:你有两个孩子和三块小饼干2个孩子的胃口值分别是1,2。你拥有的饼干数量和尺寸都足以让所有孩子满足。所以你应该输出2.
提示:
@@ -114,7 +108,7 @@ public:
## 其他语言版本
Java
### Java
```java
class Solution {
// 思路1优先考虑饼干小饼干先喂饱小胃口
@@ -153,7 +147,7 @@ class Solution {
}
```
Python
### Python
```python3
class Solution:
# 思路1优先考虑胃饼干
@@ -180,7 +174,7 @@ class Solution:
return count
```
Go
### Go
```golang
//排序后,局部最优
func findContentChildren(g []int, s []int) int {
@@ -199,7 +193,7 @@ func findContentChildren(g []int, s []int) int {
}
```
Javascript:
### Javascript
```js
var findContentChildren = function(g, s) {
g = g.sort((a, b) => a - b)
@@ -217,7 +211,7 @@ var findContentChildren = function(g, s) {
```
C:
### C
```c
int cmp(int* a, int* b) {
return *a - *b;