From b29529120be5d646700773824c43e9ace450dfd9 Mon Sep 17 00:00:00 2001 From: Andy <2311566266@qq.com> Date: Mon, 26 Jul 2021 10:10:44 +0800 Subject: [PATCH 1/3] =?UTF-8?q?Update=200225.=E7=94=A8=E9=98=9F=E5=88=97?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=A0=88.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix typo. --- problems/0225.用队列实现栈.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/0225.用队列实现栈.md b/problems/0225.用队列实现栈.md index 85b981e5..03c24132 100644 --- a/problems/0225.用队列实现栈.md +++ b/problems/0225.用队列实现栈.md @@ -38,7 +38,7 @@ https://leetcode-cn.com/problems/implement-stack-using-queues/ **队列模拟栈,其实一个队列就够了**,那么我们先说一说两个队列来实现栈的思路。 -**队列是先进先出的规则,把一个队列中的数据导入另一个队列中,数据的顺序并没有变,并有变成先进后出的顺序。** +**队列是先进先出的规则,把一个队列中的数据导入另一个队列中,数据的顺序并没有变,并没有变成先进后出的顺序。** 所以用栈实现队列, 和用队列实现栈的思路还是不一样的,这取决于这两个数据结构的性质。 From c08686cc6b26fdd92bb4726080edd0a4ee1e434e Mon Sep 17 00:00:00 2001 From: X-shuffle <53906918+X-shuffle@users.noreply.github.com> Date: Tue, 27 Jul 2021 10:48:11 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200135.=E5=88=86?= =?UTF-8?q?=E5=8F=91=E7=B3=96=E6=9E=9C=20GO=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加 0135.分发糖果 GO版本 --- problems/0135.分发糖果.md | 38 ++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/problems/0135.分发糖果.md b/problems/0135.分发糖果.md index fd791277..2d3fca84 100644 --- a/problems/0135.分发糖果.md +++ b/problems/0135.分发糖果.md @@ -175,7 +175,43 @@ class Solution: ``` Go: - +```golang +func candy(ratings []int) int { + /**先确定一边,再确定另外一边 + 1.先从左到右,当右边的大于左边的就加1 + 2.再从右到左,当左边的大于右边的就再加1 + **/ + need:=make([]int,len(ratings)) + sum:=0 + //初始化(每个人至少一个糖果) + for i:=0;i0;i--{ + if ratings[i-1]>ratings[i]{ + need[i-1]=findMax(need[i-1],need[i]+1) + } + } + //计算总共糖果 + for i:=0;inum2{ + return num1 + } + return num2 +} +``` Javascript: ```Javascript var candy = function(ratings) { From 600f82d9166a5b1a3adb3fa84a4421a979fafec7 Mon Sep 17 00:00:00 2001 From: X-shuffle <53906918+X-shuffle@users.noreply.github.com> Date: Tue, 27 Jul 2021 13:07:18 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200860.=E6=9F=A0?= =?UTF-8?q?=E6=AA=AC=E6=B0=B4=E6=89=BE=E9=9B=B6=20GO=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加 0860.柠檬水找零 GO版本 --- problems/0860.柠檬水找零.md | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/problems/0860.柠檬水找零.md b/problems/0860.柠檬水找零.md index a18c008d..0d5a7075 100644 --- a/problems/0860.柠檬水找零.md +++ b/problems/0860.柠檬水找零.md @@ -183,6 +183,45 @@ class Solution: Go: +```golang +func lemonadeChange(bills []int) bool { + //left表示还剩多少 下表0位5元的个数 ,下表1为10元的个数 + left:=[2]int{0,0} + //第一个元素不为5,直接退出 + if bills[0]!=5{ + return false + } + for i:=0;i0{ + left[0]-=1 + }else { + return false + } + } + if tmp==15{ + if left[1]>0&&left[0]>0{ + left[0]-=1 + left[1]-=1 + }else if left[1]==0&&left[0]>2{ + left[0]-=3 + }else{ + return false + } + } + } + return true +} +``` Javascript: ```Javascript