There is a special square room with mirrors on each of the four walls.  Except for the southwest corner, there are receptors on each of the remaining corners, numbered 01, and 2.

The square room has walls of length p, and a laser ray from the southwest corner first meets the east wall at a distance q from the 0th receptor.

Return the number of the receptor that the ray meets first.  (It is guaranteed that the ray will meet a receptor eventually.)

Example 1:

Input: p = 2, q = 1
Output: 2
Explanation: The ray meets receptor 2 the first time it gets reflected back to the left wall.

Note:

  1. 1 <= p <= 1000
  2. 0 <= q <= p

Approach #1: Math. [Java]

class Solution {
public int mirrorReflection(int p, int q) {
while (p % 2 == 0 && q % 2 == 0) {
p /= 2;
q /= 2;
}
if (p % 2 == 0) return 2;
else if (q % 2 == 0) return 0;
else return 1;
}
}

  

Analysis:

To show the mirror effect, we can....

Reference:

https://leetcode.com/problems/mirror-reflection/discuss/141765/Java-short-solution-with-a-sample-drawing

858. Mirror Reflection的更多相关文章

  1. 【LeetCode】858. Mirror Reflection 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  2. [LeetCode] Mirror Reflection 镜面反射

    There is a special square room with mirrors on each of the four walls.  Except for the southwest cor ...

  3. [Swift]LeetCode858. 镜面反射 | Mirror Reflection

    There is a special square room with mirrors on each of the four walls.  Except for the southwest cor ...

  4. All LeetCode Questions List 题目汇总

    All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...

  5. Swift LeetCode 目录 | Catalog

    请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift    说明:题目中含有$符号则为付费题目. 如 ...

  6. 【LeetCode】数学(共106题)

    [2]Add Two Numbers (2018年12月23日,review) 链表的高精度加法. 题解:链表专题:https://www.cnblogs.com/zhangwanying/p/979 ...

  7. LeetCode解题报告汇总! All in One!

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 把自己刷过的所有题目做一个整理,并且用简洁的语言概括了一下思路,汇总成了一个表格. 题目 ...

  8. {ICIP2014}{收录论文列表}

    This article come from HEREARS-L1: Learning Tuesday 10:30–12:30; Oral Session; Room: Leonard de Vinc ...

  9. Unity3D插件分享

    网上看到一个讲unity3D插件的,看着不错,转载过来. 本文汇总了近百个Unity3D插件,供大家参考下载. 2D_Toolkit_1.51 动画开发插件包 FingerGestures 触摸插件 ...

随机推荐

  1. Go语言实现布谷鸟过滤器

    转载请声明出处哦~,本篇文章发布于luozhiyun的博客:https://www.luozhiyun.com/archives/453 介绍 在我们工作中,如果遇到如网页 URL 去重.垃圾邮件识别 ...

  2. 关于 JMeter 5.4.1 的一点记录

    APACHE JMeter table { border: 0; border-collapse: collapse; background-color: rgba(255, 245, 218, 1) ...

  3. 面试系列二:精选大数据面试真题JVM专项-附答案详细解析

    公众号(五分钟学大数据)已推出大数据面试系列文章-五分钟小面试,此系列文章将会深入研究各大厂笔面试真题,并根据笔面试题扩展相关的知识点,助力大家都能够成功入职大厂! 大数据笔面试系列文章分为两种类型: ...

  4. go map嵌套 map的value可以是任意类型

    在日常编程中,除了使用内置的数据类型,还会使用一些复杂的自定义数据类型,比如map K为string,V为数组.先了解一下go对map的基本设定: map的key可以是任意内置的数据类型(如int), ...

  5. C++对象的生存期笔记

    下面随笔记录了C++对象的生存期知识 静态生存期 这种生存期与程序的运行期相同. 在文件作用域中声明的对象具有这种生存期. 在函数内部声明静态生存期对象,要冠以关键字static . 动态生存期 块作 ...

  6. 剑指 Offer 62. 圆圈中最后剩下的数字 + 约瑟夫环问题

    剑指 Offer 62. 圆圈中最后剩下的数字 Offer_62 题目描述 方法一:使用链表模拟 这种方法是暴力方法,时间复杂度为O(nm),在本题中数据量过大会超时. 方法二:递归方法 packag ...

  7. LeetCode-[list-of-depth-lcci]

    特定深度节点链表-求解每一层二叉树从左到右遍历形成的链表 list-of-depth-lcci 这是关于二叉树的问题,遍历每一层的结点并且存在链表中. 可以采取队列类似于广度优先搜索的方法进行搜索.每 ...

  8. 死磕Spring之IoC篇 - Spring 应用上下文 ApplicationContext

    该系列文章是本人在学习 Spring 的过程中总结下来的,里面涉及到相关源码,可能对读者不太友好,请结合我的源码注释 Spring 源码分析 GitHub 地址 进行阅读 Spring 版本:5.1. ...

  9. 为什么要从 Linux 迁移到 BSD1

    为什么要从 Linux 迁移到 BSD1 作为一个操作系统,GNU/Linux 已经变得一团糟了,因为项目的分散性,内核的臃肿,以及商业利益的玩弄.从 GNU/Linux 迁移到 BSD 有几个技术上 ...

  10. python基础(9)增强型赋值与使用普通赋值的区别

    前言 增强型赋值语句是经常被使用到的,因为从各种学习渠道中,我们能够得知i += 1的效率往往要比 i = i + 1 更高一些(这里以 += 为例,实际上增强型赋值语句不仅限于此).所以我们会乐此不 ...