Skip to content

Commit 1953ad0

Browse files
committed
Runtime: 7 ms (Top 95.56%) | Memory: 2.80 MB (Top 86.67%)
1 parent dcb4871 commit 1953ad0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Runtime: 7 ms (Top 95.56%) | Memory: 2.80 MB (Top 86.67%)
2+
3+
impl Solution {
4+
pub fn lemonade_change(bills: Vec<i32>) -> bool {
5+
bills.into_iter().try_fold([0,0],|[a,b],x|
6+
match x {
7+
5 => Some([a+1, b]),
8+
10 if a > 0 => Some([a-1,b+1]),
9+
20 if a > 0 && b > 0 => Some([a-1, b-1]),
10+
20 if a > 2 && b == 0 => Some([a-3, b]),
11+
_ => None,
12+
}
13+
).is_some()
14+
}
15+
}

0 commit comments

Comments
 (0)