Day 86: force buckle 605, flower problem

Address: leetcode-cn.com/problems/ca…

How to solve the problem by violence

var canPlaceFlowers = function(flowerbed, n) {
  const m = flowerbed.length;
  for(let i = 0; i < m; i++)
  {
    if(flowerbed[i] == 0)
    {
      if((flowerbed[i - 1] == undefined && flowerbed[i + 1] == 0) || (flowerbed[i - 1] == 0 && flowerbed[i + 1] == 0) || (flowerbed[i - 1] == 0 && flowerbed[i + 1] == undefined) || (flowerbed[i - 1] == undefined && flowerbed[i + 1] == undefined))
    {
      flowerbed[i] = 1;
      n--;
    }
    }
  }
  return (n <= 0) ? true : false;
};
Copy the code

Execution time: 84 ms, beating 86.79% of users in all JavaScript commits

Memory consumption: 39.9 MB, beating 67.14% of all JavaScript commits