博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
672. Bulb Switcher II 灯泡切换器II
阅读量:5160 次
发布时间:2019-06-13

本文共 1085 字,大约阅读时间需要 3 分钟。

 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:

  1. Flip all the lights.
  2. Flip lights with even numbers.
  3. Flip lights with odd numbers.
  4. Flip lights with (3k + 1) numbers, k = 0, 1, 2, ...

Example 1:

Input: n = 1, m = 1.Output: 2Explanation: Status can be: [on], [off]

Example 2:

Input: n = 2, m = 1.Output: 3Explanation: Status can be: [on, off], [off, on], [off, off]

Example 3:

Input: n = 3, m = 1.Output: 4Explanation: 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].

 
  1. class Solution:
  2. def flipLights(self, n, m):
  3. """
  4. :type n: int
  5. :type m: int
  6. :rtype: int
  7. """
  8. n = min(n, 3)
  9. if m == 0: return 1
  10. if m == 1: return [2, 3, 4][n-1]
  11. if m == 2: return [2, 4, 7][n-1]
  12. return [2, 4, 8][n-1]

 

转载于:https://www.cnblogs.com/xiejunzhao/p/8319167.html

你可能感兴趣的文章
Part6 数组、指针与字符串 6.13字符串
查看>>
CSS3伸缩布局Flex学习笔记
查看>>
Python(67)_写函数,判断用户传入的对象(str,列表,元组)的每一个元素是否有为空,并返回...
查看>>
C语言基础课程 第三课 ADB(Android Debug Bridge)的使用
查看>>
C/C++程序员面试大纲
查看>>
物联网能否落地?可裁剪嵌入式OS成关键
查看>>
第一阶段冲刺09
查看>>
深入理解Java中的final关键字
查看>>
在JavaScript中引用类型和值类型的区别
查看>>
机器学习 —— 概率图模型(马尔科夫与条件随机场)
查看>>
python-多线程-25
查看>>
Double类型的数据四舍五入保留小数点后两位
查看>>
NESTED LOOPS & HASH JOIN & SORT MERGE JOIN
查看>>
Oracle实例和Oracle数据库(Oracle体系结构)---转载
查看>>
软件业人才结构
查看>>
log4j.properties配置模板
查看>>
C# 拼接字符串的几种方式和性能
查看>>
Linux文件系统挂载管理
查看>>
Java路径
查看>>
Android Webview中解决H5的音视频不能自动播放的问题
查看>>