You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classSolution {
public:boolcanPlaceFlowers(vector<int>& flowerbed, int n) {
int size = flowerbed.size();
for (int i = 0; i < size; i++) {
if (flowerbed[i] == 0) {
int left = i - 1;
int right = i + 1;
if (left < 0) {
left = i;
}
if (right >= size) {
right = i;
}
if (flowerbed[left] == 0 && flowerbed[right] == 0) {
flowerbed[i] = 1;
n--;
}
}
}
return n <= 0;
}
};
단순한 배열 범위 문제
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: