Bulb Switcher II LeetCode solution in Java

1
class Solution {
2
public int flipLights(int n, int presses) {
3
// 1, 2 -> 3
4
// 1, 3 -> 2
5
// 2, 3 -> 1
6
// all on, all off, even on, odd on, 3k+1 on, 3k+0+2 on, 3k+1 w/ 2, 3k+1 w/ 3
7
if (n == 2 && presses == 1) return 3;
8
if (presses == 1)
9
return Math.min(
10
1 << Math.min(4, n),
11
4); // i chose 4 arbitarily, just has to be big enough to cover small number and less than
12
// 31
13
if (presses == 2) return Math.min(1 << Math.min(4, n), 7);
14
if (presses >= 3) return Math.min(1 << Math.min(4, n), 8);
15
return 1;
16
}
17
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0