Java-beats 80%-maybe better than the first discuss answer


  • 0
    D
    class Solution {
        public boolean canPlaceFlowers(int[] flowerbed, int n) {
            int count = 0,index = -2;
    		for(int i=0;i<flowerbed.length;i++){
    			if(flowerbed[i] == 1){
    				count += (i-index-2)/2;
    				index = i;
    			}
    		}
    		count += (flowerbed.length-index-1)/2;
    		return count>=n;
        }
    }
    

Log in to reply
 

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