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 ...
随机推荐
- 阿里Java开发规约【摘录】
1.命名规约 [强制]类名使用UpperCamelCase风格,必须遵从驼峰形式,但以下情形例外:(领域模型的相关命名)DO / BO / DTO / VO等. 正例:MarcoPolo / User ...
- 第七章· MySQL的存储引擎
一.存储引擎简介 1.文件系统: 1.1 操作系统组织和存取数据的一种机制. 1.2 文件系统是一种软件. 2.文件系统类型:ext2 3 4 ,xfs 数据 2.1 不管使用什么文件系统,数据内容 ...
- Mysql(三)-1:存储引擎
一 什么是存储引擎 mysql中建立的库===>文件夹 库中建立的表===>文件 现实生活中我们用来存储数据的文件有不同的类型,每种文件类型对应各自不同的处理机制:比如处理文本用txt类型 ...
- MySQL 安装与基本概念
Mysql版本 第一条产品线:5.0.xx及升级到5.1.xx的产品系列,这条产品线继续完善与改进其用户体验和性能,同时增加新功能,这条路线可以说是MySQL早期产品的延续系列,这一系列的产品发布情况 ...
- KeyError: 'pass_ticket'
使用wxpy模块对接微信登陆,在扫描程序弹出二维码后,使用手机微信扫描登陆之后报KeyError: 'pass_ticket'. 原因就是微信禁止该账号登陆微信网页版,如下图: 所以,去找到能让账号登 ...
- 版本控制工具 svn 二
一.图标 忽略图标 实例 二.版本 回滚 tortoisesvn ——> 版本更新——>一般情况下使用 “显示日子” 回滚 三.版本冲突 版本冲突产生原因 多人先后提交文件,每个人提交的文 ...
- demjson
demjson.decode() 可以扩展json的类型
- 牛客小白月赛12 D 月月给华华出题 (欧拉函数,数论,线筛)
链接:https://ac.nowcoder.com/acm/contest/392/D 来源:牛客网 月月给华华出题 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 131072K, ...
- python+request+HTMLTestRunner+unittest接口自动化测试框架
转自https://my.oschina.net/u/3041656/blog/820023 正在调研使用python进行自动化测试,在网上发现一篇比较好的博文,作者使用的是python3,但目前自己 ...
- Java WEB框架——SSM之Hello world
一.建立项目 先搭建一个webapp项目(要选creat from arctype) 起名 选择maven路径,settings.xml那里要选择override才可以在资源管理器中浏览.接下来直接N ...