From 55f48dc2718afa8886fcdc27a616231693b27480 Mon Sep 17 00:00:00 2001 From: fusunx <1102654482@qq.com> Date: Mon, 7 Jun 2021 21:14:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?0860.=E6=9F=A0=E6=AA=AC=E6=B0=B4=E6=89=BE?= =?UTF-8?q?=E9=9B=B6.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0860.柠檬水找零.md | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/problems/0860.柠檬水找零.md b/problems/0860.柠檬水找零.md index faee2e56..1a5634b5 100644 --- a/problems/0860.柠檬水找零.md +++ b/problems/0860.柠檬水找零.md @@ -184,7 +184,41 @@ class Solution: Go: +Javascript: +```Javascript +var lemonadeChange = function(bills) { + let fiveCount = 0 + let tenCount = 0 + let twentyCount = 0 + for(let i = 0; i < bills.length; i++) { + let bill = bills[i] + if(bill === 5) { + fiveCount += 1 + } else if (bill === 10) { + if(fiveCount > 0) { + fiveCount -=1 + tenCount += 1 + } else { + return false + } + } else { + if(tenCount > 0 && fiveCount > 0) { + twentyCount += 1 + tenCount -= 1 + fiveCount -= 1 + } else if(fiveCount >= 3) { + twentyCount += 1 + fiveCount -= 3 + } else { + return false + } + } + } + return true +}; + +``` ----------------------- * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) From 622a5e233b9935dd95dc7b1bca8d2afd08b15376 Mon Sep 17 00:00:00 2001 From: fusunx <1102654482@qq.com> Date: Mon, 7 Jun 2021 21:14:42 +0800 Subject: [PATCH 2/2] =?UTF-8?q?0860.=E6=9F=A0=E6=AA=AC=E6=B0=B4=E6=89=BE?= =?UTF-8?q?=E9=9B=B6.md=20Javascript?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0860.柠檬水找零.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/problems/0860.柠檬水找零.md b/problems/0860.柠檬水找零.md index 1a5634b5..a18c008d 100644 --- a/problems/0860.柠檬水找零.md +++ b/problems/0860.柠檬水找零.md @@ -189,7 +189,6 @@ Javascript: var lemonadeChange = function(bills) { let fiveCount = 0 let tenCount = 0 - let twentyCount = 0 for(let i = 0; i < bills.length; i++) { let bill = bills[i] @@ -204,11 +203,9 @@ var lemonadeChange = function(bills) { } } else { if(tenCount > 0 && fiveCount > 0) { - twentyCount += 1 tenCount -= 1 fiveCount -= 1 } else if(fiveCount >= 3) { - twentyCount += 1 fiveCount -= 3 } else { return false