Java short solution, beat 100%, 12ms


  • 1
    F
        public boolean canPlaceFlowers(int[] flowerbed, int n) {
            int max=0;
            for (int i = 0; i < flowerbed.length; i++) {
            	if((i==0||flowerbed[i-1]==0)&&flowerbed[i]==0&&(i+1==flowerbed.length||flowerbed[i+1]==0)){
        			flowerbed[i]=1;
        			max++;
            	}
    	}
            return  n<=max;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.