java 672. Bulb Switcher II.java

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 672. Bulb Switcher II.java相关的知识,希望对你有一定的参考价值。

/*
| m = 1 | m = 2                         | m = 3 |
|-------+-------------------------------+-------|
| a     | a = b + c                     |       |
| b     | b = a + c                     |       |
| c     | c = a + b                     |       |
| d     | d + a                         |       |
|       | d + b                         |       |
|       | d + c                         |       |
|       | a + a = b + b = c + c = d + d |  ...  |
|       |                               |  d    |
*/

class Solution {
    public int flipLights(int n, int m) {
       
        if (m == 0) return 1;
        if (n == 1) return 2;
        if (n == 2) {
            if (m == 1) {
                return 3;
            } else {
                return 4;
            }
        }
        if (n >= 3) {
            if (m == 1) return 4;
            else if (m == 2) return 7;
            else {
                return 8;
            }
        }
        return 0;
    }
}

以上是关于java 672. Bulb Switcher II.java的主要内容,如果未能解决你的问题,请参考以下文章

672. Bulb Switcher II 灯泡切换器II

java 319. Bulb Switcher.java

java 319. Bulb Switcher.java

java 319. Bulb Switcher.java

java 319. Bulb Switcher.java

java 319. Bulb Switcher.java