File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 239
239
309|[ Best Time to Buy and Sell Stock with Cooldown] ( ./0309-best-time-to-buy-and-sell-stock-with-cooldown.js ) |Medium|
240
240
316|[ Remove Duplicate Letters] ( ./0316-remove-duplicate-letters.js ) |Medium|
241
241
318|[ Maximum Product of Word Lengths] ( ./0318-maximum-product-of-word-lengths.js ) |Medium|
242
+ 319|[ Bulb Switcher] ( ./0319-bulb-switcher.js ) |Medium|
242
243
322|[ Coin Change] ( ./0322-coin-change.js ) |Medium|
243
244
326|[ Power of Three] ( ./0326-power-of-three.js ) |Easy|
244
245
328|[ Odd Even Linked List] ( ./0328-odd-even-linked-list.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 319. Bulb Switcher
3
+ * https://leetcode.com/problems/bulb-switcher/
4
+ * Difficulty: Medium
5
+ *
6
+ * There are n bulbs that are initially off. You first turn on all the bulbs, then you turn
7
+ * off every second bulb.
8
+ *
9
+ * On the third round, you toggle every third bulb (turning on if it's off or turning off if
10
+ * it's on). For the ith round, you toggle every i bulb. For the nth round, you only toggle
11
+ * the last bulb.
12
+ *
13
+ * Return the number of bulbs that are on after n rounds.
14
+ */
15
+
16
+ /**
17
+ * @param {number } n
18
+ * @return {number }
19
+ */
20
+ var bulbSwitch = function ( n ) {
21
+ return Math . floor ( n ** 0.5 ) ;
22
+ } ;
You can’t perform that action at this time.
0 commit comments