Skip to content

Commit 289352a

Browse files
committed
Add solution #672
1 parent 0f215ea commit 289352a

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@
505505
669|[Trim a Binary Search Tree](./0669-trim-a-binary-search-tree.js)|Medium|
506506
670|[Maximum Swap](./0670-maximum-swap.js)|Medium|
507507
671|[Second Minimum Node In a Binary Tree](./0671-second-minimum-node-in-a-binary-tree.js)|Easy|
508+
672|[Bulb Switcher II](./0672-bulb-switcher-ii.js)|Medium|
508509
680|[Valid Palindrome II](./0680-valid-palindrome-ii.js)|Easy|
509510
684|[Redundant Connection](./0684-redundant-connection.js)|Medium|
510511
686|[Repeated String Match](./0686-repeated-string-match.js)|Easy|

solutions/0672-bulb-switcher-ii.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* 672. Bulb Switcher II
3+
* https://leetcode.com/problems/bulb-switcher-ii/
4+
* Difficulty: Medium
5+
*
6+
* There is a room with n bulbs labeled from 1 to n that all are turned on initially, and four
7+
* buttons on the wall. Each of the four buttons has a different functionality where:
8+
* - Button 1: Flips the status of all the bulbs.
9+
* - Button 2: Flips the status of all the bulbs with even labels (i.e., 2, 4, ...).
10+
* - Button 3: Flips the status of all the bulbs with odd labels (i.e., 1, 3, ...).
11+
* - Button 4: Flips the status of all the bulbs with a label j = 3k + 1 where k = 0, 1, 2, ...
12+
* (i.e., 1, 4, 7, 10, ...).
13+
* - You must make exactly presses button presses in total. For each press, you may pick any
14+
* of the four buttons to press.
15+
*
16+
* Given the two integers n and presses, return the number of different possible statuses after
17+
* performing all presses button presses.
18+
*/
19+
20+
/**
21+
* @param {number} n
22+
* @param {number} presses
23+
* @return {number}
24+
*/
25+
var flipLights = function(n, presses) {
26+
if (presses === 0) return 1;
27+
if (n === 1) return presses >= 1 ? 2 : 1;
28+
if (n === 2) return presses === 1 ? 3 : 4;
29+
if (presses === 1) return 4;
30+
if (presses === 2) return 7;
31+
return 8;
32+
};

0 commit comments

Comments
 (0)