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 ...
随机推荐
- 在线预览(pptx、ppt、pps、docx、doc、xlsx、xls)
http://view.officeapps.live.com/op/view.aspx?src=<文档位置> 示例文档https://www.dujin.org/file/ppt/duj ...
- Migrating authentication of Samba from smbpasswd to tdb
Was addicted various After you upgrade the OS of old Samba server. Put it also was using a set of 2. ...
- (九)全志平台Tina系统量产前adb shell设密码的方法
全志平台Tina系统量产前adb shell设密码的方法[适用范围] 全志平台Tina系统 [问题现象] 通常产品量产后都想要以安全方式封闭adb shell,不允许用户或其他开发者使用,因此需要以安 ...
- 微软宣布加入机密计算联盟,与谷歌和BAT 等巨头联手保护数据安全
联盟创始成员还包括阿里巴巴.Arm.百度.谷歌.IBM.英特尔.红帽.瑞士电信和腾讯等科技公司,它提供了一个让行业聚集起来的机会,以促进使用机密计算来更好地保护数据. 建立机密计算联盟的需求源于这样一 ...
- CPU排行
早期的时候,在某个网站上面收录下来的关于CPU排行的信息,发出来让更多的人看到,希望能够帮助到一些人!
- 1.Shell脚本
1.Shell脚本 可以将Shell终端解释器当作人与计算机硬件之间的“翻译官”,它作为用户与Linux系统内部的通信媒介,除了能够支持各种变量与参数外,还提供了诸如循环.分支等高级编 程语言才有的控 ...
- 一文透彻掌握 Python 编码问题
一.当我说字符时,我在说什么? 当我们提起字符串时,每个程序员都能理解到,我们说的是一个字符序列.但是,当我们说字符时,很多人就困惑了. 写在纸上的字符很容易辨识,但是为了将不同的字符在计算机中标识出 ...
- 关于layui表格渲染templet解析单元格的问题
原文链接:https://blog.csdn.net/wyp_comeon/article/details/81735951关于表格解析自定义单元格的解析参数请先详细查看官方文档:http://www ...
- Python文件查找
#!/usr/bin/python import os import string def get_name(path_name, file_str): dir_name = ...
- Mac修改显示器使支持原生缩放
教程 直接搬运没有意义,直接放链接.地址:https://bbs.feng.com/read-htm-tid-11677019.html 若无法访问请使用网页截图备份.地址:https://img20 ...