From b6b57d8368a0912ceead4a4954bd1dd893d4bb2a Mon Sep 17 00:00:00 2001 From: cezarbbb <105843128+cezarbbb@users.noreply.github.com> Date: Sun, 31 Jul 2022 14:44:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200860.=E6=9F=A0=E6=AA=AC?= =?UTF-8?q?=E6=B0=B4=E6=89=BE=E9=9B=B6=20Rust=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加 0860.柠檬水找零 Rust版本 --- problems/0860.柠檬水找零.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/problems/0860.柠檬水找零.md b/problems/0860.柠檬水找零.md index 42e8b19a..16b89ff7 100644 --- a/problems/0860.柠檬水找零.md +++ b/problems/0860.柠檬水找零.md @@ -251,6 +251,38 @@ var lemonadeChange = function(bills) { }; ``` + +### Rust + +```Rust +impl Solution { + pub fn lemonade_change(bills: Vec) -> bool { + let mut five = 0; + let mut ten = 0; + // let mut twenty = 0; + for bill in bills { + if bill == 5 { five += 1; } + if bill == 10 { + if five <= 0 { return false; } + ten += 1; + five -= 1; + } + if bill == 20 { + if five > 0 && ten > 0 { + five -= 1; + ten -= 1; + // twenty += 1; + } else if five >= 3 { + five -= 3; + // twenty += 1; + } else { return false; } + } + } + true + } +} +``` + ### C ```c bool lemonadeChange(int* bills, int billsSize){