-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution605_2.java
More file actions
34 lines (33 loc) · 952 Bytes
/
Copy pathsolution605_2.java
File metadata and controls
34 lines (33 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public class solution605_2 {
public boolean canPlaceFlowers(int[] flowerbed, int n) {
int cnt = 0;
for(int i = 0;i<flowerbed.length;i++)
{
if(flowerbed[i] == 0)
{
if(i == 0)
{
if(flowerbed.length==1||flowerbed[i+1] == 0)
{
cnt++;
flowerbed[i] = 1;
}
}else if(i == flowerbed.length-1)
{
if(flowerbed[i-1] == 0)
{
flowerbed[i] = 1;
cnt++;
}
}else{
if(flowerbed[i-1] == 0 && flowerbed[i+1] == 0)
{
flowerbed[i] = 1;
cnt++;
}
}
}
}
return cnt>=n;
}
}