當前位置:
首頁 >
天池 在线编程 到达终点
發布時間:2024/7/5
43
豆豆
生活随笔
收集整理的這篇文章主要介紹了
天池 在线编程 到达终点
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 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] 移動的次數可以是0次。 示例 1: 輸入: start = [1, 1] target = [5, 2] 輸出: True 解釋: (1, 1) -> (1, 2) -> (3, 2) -> (5, 2), 你應該返回True示例 2: 輸入: start = [1, 2] target = [3, 4] 輸出: False 解釋: [1, 2] 根據移動規則不能到達 [3, 4] 所以你應該返回False.示例 3: 輸入: start = [2, 1] target = [4, 1] 輸出: True 解釋: (2, 1) -> (3, 1) -> (4, 1), 你應該返回True.https://tianchi.aliyun.com/oj/338602522508251883/378934605959598749
2. 解題
- 從終點往回推,大的坐標減去小的坐標
我的CSDN博客地址 https://michael.blog.csdn.net/
長按或掃碼關注我的公眾號(Michael阿明),一起加油、一起學習進步!
總結
以上是生活随笔為你收集整理的天池 在线编程 到达终点的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode 1739. 放置盒子(
- 下一篇: LeetCode 2145. 统计隐藏数