LC 672. Bulb Switcher II
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].
Runtime: 4 ms, faster than 29.00% of C++ online submissions for Bulb Switcher II.
找规律题。
class Solution {
public:
int flipLights(int n, int m) {
if(m == ) return ;
if(n == ) return ;
if(n == && m == ) return ;
if(n == ) return ;
if(m==) return ;
if(m == ) return ;
return ;
}
};
LC 672. Bulb Switcher II的更多相关文章
- 【LeetCode】672. Bulb Switcher II 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- [LeetCode] Bulb Switcher II 灯泡开关之二
There is a room with n lights which are turned on initially and 4 buttons on the wall. After perform ...
- [Swift]LeetCode672. 灯泡开关 Ⅱ | Bulb Switcher II
There is a room with n lights which are turned on initially and 4 buttons on the wall. After perform ...
- [LeetCode] Bulb Switcher 灯泡开关
There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every ...
- LeetCode 319 ——Bulb Switcher——————【数学技巧】
319. Bulb Switcher My Submissions QuestionEditorial Solution Total Accepted: 15915 Total Submissions ...
- 【LeetCode】319. Bulb Switcher 解题报告(Python)
[LeetCode]319. Bulb Switcher 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/bulb ...
- LeetCode Bulb Switcher 319
变换灯泡颜色 There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off ...
- Leetcode Bulb Switcher
There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every ...
- Bulb Switcher
There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every ...
随机推荐
- c#类生成表
第一步: 创建MyContext类 public class MyContext:DbContext { public MyContext():base() { } public DbSet<U ...
- Delphi WaitCommEvent函数
- jsp页面获取浏览器中的请求 或者 转发过来的请求值
jsp页面中的$(param.xxx) $(param.user)相当于<%=request.getParameter("user")%>
- BZOJ 1003 最短路dp
物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线,以便对整个运输过程实施严格的管理和跟踪.由于各种因 ...
- JS 数组相关的操作函数
// 1.数组拼接 concat() var a = [1, 2]; var b = [3, 4]; console.log(a.concat(b)); // [1, 2, 3, 4] // 2.数组 ...
- docker安装rocketmq
一.单机部署 1.拉取镜像:foxiswho/rocketmq:server cabel/rocketmq:broker styletang/rocketmq-console-ng 2.创建目录:d ...
- Suse环境下编译linux-2.6.24内核
Suse环境下编译linux-2.6.24内核 1.下载linux-2.6.24内核源码: https://mirrors.edge.kernel.org/pub/linux/kernel/v2.6/ ...
- vue cli3 + cube-ui 配置rem踩坑记录
在install cube-ui时,选择了后编译,选中使用rem的时候会发现,怎么刷新页面的html字体被设置成了37.5px 感觉太大了,于是去寻找修改的办法,第一反应是webpack的配置,于是去 ...
- Servlet中的乱码问题及解决办法
假设现在有个form表单,当页面中提交一个包含中文的请求时,在服务端有可能出现中文乱码问题. <!DOCTYPE html> <html> <head> <m ...
- httpclient个人理解
httpclient:模拟浏览器发送请求,服务器会响应数据,用心区域网内 不同系统间的请求调用 依赖 httpclient.jar和httpcore.jar需要同时纯在 <dependency ...