Bulb Switcher II
Thoughts
Code
class Solution {
public int flipLights(int n, int m) {
if (m == 0) {
return 1;
}
if (n == 1) {
// o可以是亮或灭
return 2;
}
if (n == 2 && m == 1) {
return 3;
}
if (n == 2) {
return 4;
}
if (m == 1) {
return 4; // 对应1, 2, 3, 4操作
}
if (m == 2) {
return 7; // 对应 o, 14, 24, 34, 12 = 3, 13 = 2, 23 = 1
}
return 8;
}
}Analysis
Previous1247. Minimum Swaps to Make Strings EqualNext1503. Last Moment Before All Ants Fall Out of a Plank
Last updated