leetcode 672. Bulb Switcher II
来源:互联网 发布:js div 轮播代码 编辑:程序博客网 时间:2024/06/07 17:35
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].
看到有些答案,再一次感觉到智商被碾压了
建议和leetcode 319. Bulb Switcher 轮流开关灯泡 一起学习
代码如下:
#include <iostream>#include <vector>#include <map>#include <set>#include <queue>#include <stack>#include <string>#include <climits>#include <algorithm>#include <sstream>#include <functional>#include <bitset>#include <numeric>#include <cmath>#include <regex>using namespace std;class Solution{public: int flipLights(int n, int m) { n = min(n, 3); return min(1 << n, 1 + m * n); }};
- leetcode 672. Bulb Switcher II
- LeetCode: 672. Bulb Switcher II
- LeetCode 672. Bulb Switcher II
- leetcode 672. Bulb Switcher II
- leetcode 672. Bulb Switcher II
- LEETCODE 48 672. Bulb Switcher II
- 319. Bulb Switcher && 672. Bulb Switcher II
- [leetcode] 319. Bulb Switcher
- leetcode Bulb Switcher
- [Leetcode]Bulb Switcher
- 【Leetcode】Bulb Switcher
- leetcode 319 Bulb Switcher
- Bulb Switcher | LeetCode
- Leetcode-319 Bulb Switcher
- Leetcode: Bulb Switcher
- leetcode 319. Bulb Switcher
- 【LEETCODE】319-Bulb Switcher
- leetcode之Bulb Switcher
- nginx日志记录切割
- WMencoder9 在CoCreateInstance奔溃问题
- sublime text 多行代码注释快捷键
- Linux 图形界面问题
- 进级的RecyclerView——LRecyclerView
- leetcode 672. Bulb Switcher II
- Spark内核:RDD的算子
- Redis数据结构-SortedSet
- 移植3.4.2内核
- js中==与===的区别
- 兼容蓝牙 4.1、4.2 和 5 的低功耗蓝牙 SoC 和工具可应对 IoT 挑战(第 2 部分)---凯利讯半导体
- Ping的本质
- 前端学记之html5-1
- 在python&numpy中切片(slice)