Skip to content

Commit d86af65

Browse files
committed
Update solution 605 [Java]
1 parent 2d1dc7a commit d86af65

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

solution/605.Can Place Flowers/README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
假设你有一个很长的花坛,一部分地块种植了花,另一部分却没有。可是,花卉不能种植在相邻的地块上,它们会争夺水源,两者都会死去。
55

6-
给定一个花坛(表示为一个数组包含 0 和 1,其中 0 表示没种植花,1 表示种植了花),和一个数 `n` 。能否在不打破种植规则的情况下种入 `n` 朵花?能则返回 True,不能则返回 False。
6+
给定一个花坛(表示为一个数组包含 0 和 1,其中 0 表示没种植花,1 表示种植了花),和一个数 `n` 。能否在不打破种植规则的情况下种入 `n` 朵花?能则返回 `True`,不能则返回 `False`
77

88
**示例 1:**
99
```
@@ -34,9 +34,7 @@ class Solution {
3434
int len = flowerbed.length;
3535
int cnt = 0;
3636
for (int i = 0; i < len; ++i) {
37-
if (flowerbed[i] == 0
38-
&& (i == 0 || flowerbed[i - 1] == 0)
39-
&& (i == len - 1 || flowerbed[i + 1] == 0)) {
37+
if (flowerbed[i] == 0 && (i == 0 || flowerbed[i - 1] == 0) && (i == len - 1 || flowerbed[i + 1] == 0)) {
4038
++cnt;
4139
flowerbed[i] = 1;
4240
}

solution/605.Can Place Flowers/Solution.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ public boolean canPlaceFlowers(int[] flowerbed, int n) {
33
int len = flowerbed.length;
44
int cnt = 0;
55
for (int i = 0; i < len; ++i) {
6-
if (flowerbed[i] == 0
7-
&& (i == 0 || flowerbed[i - 1] == 0)
8-
&& (i == len - 1 || flowerbed[i + 1] == 0)) {
6+
if (flowerbed[i] == 0 && (i == 0 || flowerbed[i - 1] == 0) && (i == len - 1 || flowerbed[i + 1] == 0)) {
97
++cnt;
108
flowerbed[i] = 1;
119
}

0 commit comments

Comments
 (0)