From 9bd3c4d3549516cd469e9b4ab8580c326741479a Mon Sep 17 00:00:00 2001 From: X-shuffle <53906918+X-shuffle@users.noreply.github.com> Date: Wed, 21 Jul 2021 22:32:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A00455.=E5=88=86=E5=8F=91?= =?UTF-8?q?=E9=A5=BC=E5=B9=B2=20go=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加0455.分发饼干 go版本 --- problems/0455.分发饼干.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/problems/0455.分发饼干.md b/problems/0455.分发饼干.md index 4814d414..6b121e36 100644 --- a/problems/0455.分发饼干.md +++ b/problems/0455.分发饼干.md @@ -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