天池 在线编程 到达终点
文章目錄
- 1. 題目
- 2. 解題
1. 題目
描述
A robot is located in a pair of integer coordinates (x, y). It must be moved to a location with another set of coordinates. Though the bot can move any number of times, it can only make the following two types of moves:
- From location (x, y) to location (x + y, y)
- From location (x, y) to location (x, x + y)
Given the start coordinates and the end coordinates of the target, if the robot can reach the end coordinates according to the given motion rules, you should return true, otherwise you should return false.
x 和 y 的范圍是: [1, 1 000 000 000] 移動的次數(shù)可以是0次。 示例 1: 輸入: start = [1, 1] target = [5, 2] 輸出: True 解釋: (1, 1) -> (1, 2) -> (3, 2) -> (5, 2), 你應(yīng)該返回True示例 2: 輸入: start = [1, 2] target = [3, 4] 輸出: False 解釋: [1, 2] 根據(jù)移動規(guī)則不能到達(dá) [3, 4] 所以你應(yīng)該返回False.示例 3: 輸入: start = [2, 1] target = [4, 1] 輸出: True 解釋: (2, 1) -> (3, 1) -> (4, 1), 你應(yīng)該返回True.https://tianchi.aliyun.com/oj/338602522508251883/378934605959598749
2. 解題
- 從終點(diǎn)往回推,大的坐標(biāo)減去小的坐標(biāo)
我的CSDN博客地址 https://michael.blog.csdn.net/
長按或掃碼關(guān)注我的公眾號(Michael阿明),一起加油、一起學(xué)習(xí)進(jìn)步!
總結(jié)
以上是生活随笔為你收集整理的天池 在线编程 到达终点的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode 1739. 放置盒子(
- 下一篇: LeetCode MySQL 1890.