Leetcode in Java && Oracle
424 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2023-05-26_12-11-11.png
34.9 KB
Runtime1 msBeats99.47%
Memory44.2 MBBeats45.81%
#N605. Can Place Flowers
problem link
#solution
class Solution {
public boolean canPlaceFlowers(int[] f, int n) {
int l = f.length;
if(n==0) return true;
if(l==1) return f[0]==0 && n == 1;

for(int i=0; i<l; i++){
if(i==0 && f[0] + f[1] == 0) {
n--;
i++;
}
else if(i==l-1 && f[l-1] + f[l-2]==0) {
n--;
i++;
}
else if(i>0 && i<l-1 && f[i]+f[i-1]+f[i+1]==0){
n--;
i++;
}
}
return n<=0;
}
}
👍5