nuxy / leetcode-605

Benchmark created on


Description

Can Place Flowers

Setup

const canPlaceFlowers = function(flowerbed, n) {
  let lastPlot, nextPlot;

  const len = flowerbed.length;

  let bool = false;

  for (let i = 0; i < len; i++) {
    currPlot = flowerbed[i];
    lastPlot = flowerbed[i - 1];
    nextPlot = flowerbed[i + 1];

    if (currPlot === 0 && lastPlot === 0 && nextPlot === 0 && ((i + n) < len - 1)) {      
      bool = true;
      break;
    }
  }

  return bool;
};

Test runner

Ready to run.

Testing in
TestOps/sec
Test 1
canPlaceFlowers([1,0,0,0,1], 1); // true
ready
Test 2
canPlaceFlowers([1,0,0,0,1], 2); // false
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.