JAVA_Can Place Flowers_LeetCode 605


JAVA_Can Place Flowers_LeetCode 605

JAVA_Can Place Flowers_LeetCode 605 풀이 class Solution { public boolean canPlaceFlowers(int[] flowerbed, int n) { int cnt = 0, N = flowerbed.length; for (int i = 0; i < N; i++) { if ((flowerbed[i] == 0) && ((i == 0 || flowerbed[i-1] == 0) && (i == N-1 || flowerbed[i+1] == 0))) { cnt++; flowerbed[i] = 1; } } return cnt >= n; } } * 출처 Can Place Flowers - LeetCode Can Place Flowers - You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be plante...


#CanPlaceFlowers_LeetCode605 #JAVA #JAVA_CanPlaceFlowers #JAVA_CanPlaceFlowers_LeetCode605 #JAVA_LeetCode605

원문링크 : JAVA_Can Place Flowers_LeetCode 605