增加0455.分发饼干 go版本

增加0455.分发饼干 go版本
This commit is contained in:
X-shuffle
2021-07-21 22:32:35 +08:00
committed by GitHub
parent 6166d9063b
commit 9bd3c4d354

View File

@ -146,6 +146,23 @@ class Solution:
return res return res
``` ```
Go Go
```golang
//排序后,局部最优
func findContentChildren(g []int, s []int) int {
sort.Ints(g)
sort.Ints(s)
// 从小到大
child := 0
for sIdx := 0; child < len(g) && sIdx < len(s); sIdx++ {
if s[sIdx] >= g[child] {//如果饼干的大小大于或等于孩子的为空则给与,否则不给予,继续寻找选一个饼干是否符合
child++
}
}
return child
}
Javascript: Javascript:
```Javascript ```Javascript