mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
添加 0860.柠檬水找零 Rust版本
添加 0860.柠檬水找零 Rust版本
This commit is contained in:
@ -251,6 +251,38 @@ var lemonadeChange = function(bills) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Rust
|
||||||
|
|
||||||
|
```Rust
|
||||||
|
impl Solution {
|
||||||
|
pub fn lemonade_change(bills: Vec<i32>) -> 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
|
||||||
```c
|
```c
|
||||||
bool lemonadeChange(int* bills, int billsSize){
|
bool lemonadeChange(int* bills, int billsSize){
|
||||||
|
Reference in New Issue
Block a user