Skip to content

Commit 5bff8f4

Browse files
committed
add solution in rust: 605. Can Place Flowers
Signed-off-by: rajput-hemant <rajput.hemant2001@gmail.com>
1 parent f1f4341 commit 5bff8f4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
impl Solution {
2+
pub fn can_place_flowers(flowerbed: Vec<i32>, mut n: i32) -> bool {
3+
let mut empty = if flowerbed[0] == 0 { 1 } else { 0 };
4+
5+
for &x in &flowerbed {
6+
if x == 0 {
7+
empty += 1;
8+
} else {
9+
n -= (empty - 1) / 2;
10+
empty = 0;
11+
}
12+
}
13+
14+
n -= empty / 2;
15+
16+
n <= 0
17+
}
18+
}

0 commit comments

Comments
 (0)