Skip to content

Commit 43e1ef4

Browse files
committed
Add solution #319
1 parent 0e52e02 commit 43e1ef4

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@
239239
309|[Best Time to Buy and Sell Stock with Cooldown](./0309-best-time-to-buy-and-sell-stock-with-cooldown.js)|Medium|
240240
316|[Remove Duplicate Letters](./0316-remove-duplicate-letters.js)|Medium|
241241
318|[Maximum Product of Word Lengths](./0318-maximum-product-of-word-lengths.js)|Medium|
242+
319|[Bulb Switcher](./0319-bulb-switcher.js)|Medium|
242243
322|[Coin Change](./0322-coin-change.js)|Medium|
243244
326|[Power of Three](./0326-power-of-three.js)|Easy|
244245
328|[Odd Even Linked List](./0328-odd-even-linked-list.js)|Medium|

solutions/0319-bulb-switcher.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
};

0 commit comments

Comments
 (0)