858. Mirror Reflection
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
0
,1
, and2
.The square room has walls of length
p
, and a laser ray from the southwest corner first meets the east wall at a distanceq
from the0
th 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 <= p <= 1000
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:
858. Mirror Reflection的更多相关文章
- 【LeetCode】858. Mirror Reflection 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- [LeetCode] Mirror Reflection 镜面反射
There is a special square room with mirrors on each of the four walls. Except for the southwest cor ...
- [Swift]LeetCode858. 镜面反射 | Mirror Reflection
There is a special square room with mirrors on each of the four walls. Except for the southwest cor ...
- All LeetCode Questions List 题目汇总
All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...
- Swift LeetCode 目录 | Catalog
请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift 说明:题目中含有$符号则为付费题目. 如 ...
- 【LeetCode】数学(共106题)
[2]Add Two Numbers (2018年12月23日,review) 链表的高精度加法. 题解:链表专题:https://www.cnblogs.com/zhangwanying/p/979 ...
- LeetCode解题报告汇总! All in One!
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 把自己刷过的所有题目做一个整理,并且用简洁的语言概括了一下思路,汇总成了一个表格. 题目 ...
- {ICIP2014}{收录论文列表}
This article come from HEREARS-L1: Learning Tuesday 10:30–12:30; Oral Session; Room: Leonard de Vinc ...
- Unity3D插件分享
网上看到一个讲unity3D插件的,看着不错,转载过来. 本文汇总了近百个Unity3D插件,供大家参考下载. 2D_Toolkit_1.51 动画开发插件包 FingerGestures 触摸插件 ...
随机推荐
- 采用lua脚本获取mysql、redis数据以及jwt的校验
一.安装配置Openresty 1,安装 wget https://openresty.org/download/ngx_openresty-1.9.7.1.tar.gz # 下载 tar xzvf ...
- Java 队列同步器 AQS
本文部分摘自<Java 并发编程的艺术> 概述 队列同步器 AbstractQueuedSynchronize(以下简称同步器),是用来构建锁(Lock)或者其他同步组件(JUC 并发包) ...
- eureka server 配置
启动类 import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure. ...
- PAT-1151(LCA in a Binary Tree)+最近公共祖先+二叉树的中序遍历和前序遍历
LCA in a Binary Tree PAT-1151 本题的困难在于如何在中序遍历和前序遍历已知的情况下找出两个结点的最近公共祖先. 可以利用据中序遍历和前序遍历构建树的思路,判断两个结点在根节 ...
- sprintgboot+springsecurity的跨域问题,
整个项目是使用前后端分离的形式开发,登录接口部分出现了问题, 重写了security的登录接口,返回json数据 到这一步已经没有没有问题了,使用postman测试,也可以看到接口返回的结果,但是使用 ...
- pytest+jenkins+allure 生成测试报告发送邮件
前言第一部分:Pycharm for Gitee1. pycharm安装gitee插件2. gitee关联本地Git快速设置- 如果你知道该怎么操作,直接使用下面的地址简易的命令行入门教程:3. Gi ...
- golang 三维向量相关操作
package vector import ( "math" "fmt" )// 三维向量:(x,y,z) type Vector3 struct { X fl ...
- MySQL按天备份二进制日志
#!/usr/bin/env python # -*- coding:utf-8 -*- # Author:guozhen.zhang import MySQLdbimport timeimp ...
- 一个名叫Sentinel-Rules-SDK的组件,使得Sentinel的流控&熔断规则的配置更加方便
原文链接:一个名叫Sentinel-Rules-SDK的组件,使得Sentinel的流控&熔断规则的配置更加方便 1 Sentinel 是什么? 随着微服务的流行,服务和服务之间的稳定性变得越 ...
- Android应用程序的进程创建过程
目录 前言 步骤 step1 Ams发起请求startProcessLocked step2 Zygote收到请求 step3 handleChildProc -- 进入子进程的世界 step4 Ru ...