Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2bacf12

Browse files
authored
feat: add rust solution to lc problem: No.0605 (doocs#1591)
No.0605.Can Place Flowers
1 parent f3f5f24 commit 2bacf12

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

‎solution/0600-0699/0605.Can Place Flowers/README.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,27 @@ class Solution {
148148
}
149149
```
150150

151+
### **Rust**
152+
153+
```rust
154+
impl Solution {
155+
pub fn can_place_flowers(flowerbed: Vec<i32>, n: i32) -> bool {
156+
let (mut flowers, mut cnt) = (vec![0], 0);
157+
flowers.append(&mut flowerbed.clone());
158+
flowers.push(0);
159+
160+
for i in 1..flowers.len() - 1 {
161+
let (l, r) = (flowers[i - 1], flowers[i + 1]);
162+
if l + flowers[i] + r == 0 {
163+
flowers[i] = 1;
164+
cnt += 1;
165+
}
166+
}
167+
cnt >= n
168+
}
169+
}
170+
```
171+
151172
### **...**
152173

153174
```

‎solution/0600-0699/0605.Can Place Flowers/README_EN.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,27 @@ class Solution {
129129
}
130130
```
131131

132+
### **Rust**
133+
134+
```rust
135+
impl Solution {
136+
pub fn can_place_flowers(flowerbed: Vec<i32>, n: i32) -> bool {
137+
let (mut flowers, mut cnt) = (vec![0], 0);
138+
flowers.append(&mut flowerbed.clone());
139+
flowers.push(0);
140+
141+
for i in 1..flowers.len() - 1 {
142+
let (l, r) = (flowers[i - 1], flowers[i + 1]);
143+
if l + flowers[i] + r == 0 {
144+
flowers[i] = 1;
145+
cnt += 1;
146+
}
147+
}
148+
cnt >= n
149+
}
150+
}
151+
```
152+
132153
### **...**
133154

134155
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
impl Solution {
2+
pub fn can_place_flowers(flowerbed: Vec<i32>, n: i32) -> bool {
3+
let (mut flowers, mut cnt) = (vec![0], 0);
4+
flowers.append(&mut flowerbed.clone());
5+
flowers.push(0);
6+
7+
for i in 1..flowers.len() - 1 {
8+
let (l, r) = (flowers[i - 1], flowers[i + 1]);
9+
if l + flowers[i] + r == 0 {
10+
flowers[i] = 1;
11+
cnt += 1;
12+
}
13+
}
14+
cnt >= n
15+
}
16+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /