Skip to content

Commit 7aee010

Browse files
committed
Update bulb-switcher.py
1 parent fae3225 commit 7aee010

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Python/bulb-switcher.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
# Time: O(1)
22
# Space: O(1)
33

4+
# There are n bulbs that are initially off.
5+
# You first turn on all the bulbs. Then,
6+
# you turn off every second bulb. On the
7+
# third round, you toggle every third bulb
8+
# (turning on if it's off or turning off if
9+
# it's on). For the nth round, you only
10+
# toggle the last bulb. Find how many bulbs
11+
# are on after n rounds.
12+
#
13+
# Example:
14+
#
15+
# Given n = 3.
16+
#
17+
# At first, the three bulbs are [off, off, off].
18+
# After first round, the three bulbs are [on, on, on].
19+
# After second round, the three bulbs are [on, off, on].
20+
# After third round, the three bulbs are [on, off, off].
21+
#
22+
# So you should return 1, because there is
23+
# only one bulb is on.
24+
425
class Solution(object):
526
def bulbSwitch(self, n):
627
"""

0 commit comments

Comments
 (0)