LeetCode-in-Java

672. Bulb Switcher II

Medium

There is a room with n bulbs labeled from 1 to n that all are turned on initially, and four buttons on the wall. Each of the four buttons has a different functionality where:

You must make exactly presses button presses in total. For each press, you may pick any of the four buttons to press.

Given the two integers n and presses, return the number of different possible statuses after performing all presses button presses.

Example 1:

Input: n = 1, presses = 1

Output: 2

Explanation: Status can be:

Example 2:

Input: n = 2, presses = 1

Output: 3

Explanation: Status can be:

Example 3:

Input: n = 3, presses = 1

Output: 4

Explanation: Status can be:

Constraints:

Solution

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