We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f89d5c9 commit e3d21f3Copy full SHA for e3d21f3
src/bin/can-place-flowers.rs
@@ -0,0 +1,35 @@
1
+fn main() {}
2
+
3
+struct Solution;
4
5
+impl Solution {
6
+ pub fn can_place_flowers(flowerbed: Vec<i32>, n: i32) -> bool {
7
+ let mut f = flowerbed;
8
+ let mut n = n;
9
10
+ for i in 0..f.len() {
11
+ if i == 0 {
12
+ if f[i] == 0 && f.get(i + 1).unwrap_or(&0) == &0 {
13
+ f[i] = 1;
14
+ n -= 1;
15
+ }
16
+ } else if i == f.len() - 1 {
17
+ if f[i] == 0 && f.get(i - 1).unwrap_or(&0) == &0 {
18
19
20
21
+ } else {
22
+ if f[i] == 0 && f[i - 1] == 0 && f[i + 1] == 0 {
23
24
25
26
27
28
+ if n <= 0 {
29
+ return true;
30
31
32
33
+ false
34
35
+}
0 commit comments