leetcode

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit d2a8aa6e7567513e16896914d9129e70cd3f1f5c
parent 8247992a3f2590d0afd4cc3c153c2480a100b653
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date:   Thu, 27 Apr 2023 10:02:31 -0500

Completed bulb-switcher using sqrt with js

Diffstat:
Abulb-switcher/bulb-switcherV2.js | 24++++++++++++++++++++++++
1 file changed, 24 insertions(+), 0 deletions(-)

diff --git a/bulb-switcher/bulb-switcherV2.js b/bulb-switcher/bulb-switcherV2.js @@ -0,0 +1,24 @@ +//Manual solution finding sqrt without built in method. +//Runtime: 64ms Beats: 12.7% +//Memory: 42.3MB Beats: 6.90% +/** + * @param {number} n + * @return {number} + */ +var bulbSwitch = function(n) { + let sqrt = 0; + if(n == 0){ + return 0; + } + if(n <= 3){ + return 1; + } + for(var i = 0 ; i < n / 2 + 2; ++i){ + if(i * i > n){ + return i - 1; + } + } + + + return 0; +};