mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
增加0455.分发饼干 go版本
增加0455.分发饼干 go版本
This commit is contained in:
@ -146,6 +146,23 @@ class Solution:
|
||||
return res
|
||||
```
|
||||
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
|
||||
|
Reference in New Issue
Block a user