leetcode672

package
v0.0.0-...-a94f1ba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2024 License: BSD-3-Clause Imports: 0 Imported by: 0

README

Bulb Switcher II

6 个灯泡为一个循环(由第 4 个方法决定),共存在 8 种情况:

1 2 3 4 5 6
💡 💡 💡 💡 💡 💡
💡 - 💡 - 💡 -
- 💡 - 💡 - 💡
- 💡 💡 - 💡 💡
💡 - - 💡 - -
- - 💡 💡 💡 -
💡 💡 - - - 💡
- - - - - -

m 次数的不同结果:

  • 0 次 ① 共 1 种可能;
  • 1 次 ⑧②③④ 共 4 种可能;
  • 2 次 ①③②⑤|③①⑧⑥|②⑧①⑦|⑤⑥⑦① 共 7 种可能;
  • 3 次 ④ 可以出现,所有共 8 种可能;
  • 更多,8 种可能都能出现。

所以:

  • m = 0 有 1 种情况;
  • m > 0
    • n = 1 有 2 种情况;
    • n = 2
      • m = 1 有 3 种情况;
      • m > 1 有 4 种情况;
    • n > 2
      • m = 1 有 4 种情况;
      • m = 2 有 7 种情况;
      • m > 2 有 8 种情况;

Documentation

Overview

* @lc app=leetcode id=672 lang=golang * * [672] Bulb Switcher II * * https://leetcode.com/problems/bulb-switcher-ii/description/ * * algorithms * Medium (50.52%) * Likes: 111 * Dislikes: 786 * Total Accepted: 11.3K * Total Submissions: 22.3K * Testcase Example: '1\n1' * * There is a room with n lights which are turned on initially and 4 buttons on * the wall. After performing exactly m unknown operations towards buttons, you * need to return how many different kinds of status of the n lights could be. * * Suppose n lights are labeled as number [1, 2, 3 ..., n], function of these 4 * buttons are given below: * * * Flip all the lights. * Flip lights with even numbers. * Flip lights with odd numbers. * Flip lights with (3k + 1) numbers, k = 0, 1, 2, ... * * * * * Example 1: * * * Input: n = 1, m = 1. * Output: 2 * Explanation: Status can be: [on], [off] * * * * * Example 2: * * * Input: n = 2, m = 1. * Output: 3 * Explanation: Status can be: [on, off], [off, on], [off, off] * * * * * Example 3: * * * Input: n = 3, m = 1. * Output: 4 * Explanation: Status can be: [off, on, off], [on, off, on], [off, off, off], * [off, on, on]. * * * * * Note: n and m both fit in range [0, 1000]. *

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL