Skip to content

Commit

Permalink
Merge pull request 7oSkaaa#1006 from RotenKiwi/main
Browse files Browse the repository at this point in the history
Create 27- Bulb Switcher (RotenKiwi).cpp
  • Loading branch information
aboelsooud committed Apr 28, 2023
2 parents e8ea0c3 + 910ae4e commit 4fa3539
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 04- April/27- Bulb Switcher/27- Bulb Switcher (RotenKiwi).cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Author: RotenKiwi

class Solution {
public:
int bulbSwitch(int num) {
if (0 == num) { return 0; } // Avoid zero divide
int n = (num / 2) + 1; // Initial estimate, never low
int n1 = (n + (num / n)) / 2;
while (n1 < n) {
n = n1;
n1 = (n + (num / n)) / 2;
} // end while
return n;
}
};

0 comments on commit 4fa3539

Please sign in to comment.