题目标签:Math 题目让我们判断机器人是否是一直在走一个圈. 当我们把 instructions 走完一遍时候: 1. 如果机器人回到了原点,那么它是在走一个圈. 2. 如果机器人的方向没有改变,那么它一直在朝一个方向走,就算重复instructions也不可能会走一个圈. 所以当机器人的方向改变的话,在重复instructions,它一定会走回原点,完成一个圈. 具体看code. Java Solution: Runtime:  0 ms, faster than 100 % Memory…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 找规律 日期 题目地址:https://leetcode.com/problems/robot-bounded-in-circle/ 题目描述 On an infinite plane, a robot initially stands at (0, 0) and faces north. The robot can receive one of t…
题目如下: On an infinite plane, a robot initially stands at (0, 0) and faces north.  The robot can receive one of three instructions: "G": go straight 1 unit; "L": turn 90 degrees to the left; "R": turn 90 degress to the right. T…
本题题意: 一开始一个机器人站在了(0,0)上,面朝的方向是北,收到三个序列G,L,R. G:直走 L:向左转 R:向右转 按序执行,永远重复. 返回TRUE,如果处在一个圈. 第一个卡住的点: 1.疑惑于机器人会不会不经过原点,然后还会出现一个圈? 不会.若在固定路线转圈,肯定是重复了若干次,回到了原点.否则路线是不能固定的. idea: 1.如果第一次执行完一串指令后,就在原点,则一定是固定路线. 2.如果执行完一串指令后,不在原点,新的方向是dir,则有下面的结论: dir不是北方,就一定…
题目地址 : https://leetcode-cn.com/problems/robot-bounded-in-circle/ 在无限的平面上,机器人最初位于 (0, 0) 处,面朝北方.机器人可以接受下列三条指令之一: "G":直走 1 个单位"L":左转 90 度"R":右转 90 度机器人按顺序执行指令 instructions,并一直重复它们. 只有在平面中存在环使得机器人永远无法离开时,返回 true.否则,返回 false. 示例…
描述: 在无限的平面上,机器人最初位于 (0, 0) 处,面朝北方.机器人可以接受下列三条指令之一: "G":直走 1 个单位 "L":左转 90 度 "R":右转 90 度 机器人按顺序执行指令 instructions,并一直重复它们. 只有在平面中存在环使得机器人永远无法离开时,返回 true.否则,返回 false. 示例 1: 输入:"GGLLGG" 输出:true 解释: 机器人从 (0,0) 移动到 (0,2),…
[LeetCode]657. Judge Route Circle 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/judge-route-circle/description/ 题目描述: Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which mea…
原题链接在这里:https://leetcode.com/problems/robot-room-cleaner/ 题目: Given a robot cleaner in a room modeled as a grid. Each cell in the grid can be empty or blocked. The robot cleaner with 4 given APIs can move forward, turn left or turn right. Each turn i…
Given a robot cleaner in a room modeled as a grid. Each cell in the grid can be empty or blocked. The robot cleaner with 4 given APIs can move forward, turn left or turn right. Each turn it made is 90 degrees. When it tries to move into a blocked cel…
There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves. The move sequence is represented by a string, and the character moves[i] repre…
题目要求 There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves. The move sequence is represented by a string, and the character moves[i]…
题目: There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves. The move sequence is represented by a string, and the character moves[i] r…
https://leetcode-cn.com/problems/robot-return-to-origin/ 设置 flagUD 记录机器人相对于原点在纵向上的最终位置 flagRL 记录机器人相对于原点在横向上的最终位置 如果最终 flagUD==0 && flagRL==0 ,说明机器人的最终位置与原点相同 class Solution { public boolean judgeCircle(String moves) { int flagRL = 0; int flagUD =…
周日的比赛的时候正在外面办事,没有参加.赛后看了下题目,几道题除了表面要考的内容,还是有些能发散扩展的地方. 做题目不是最终目的,通过做题发现知识盲区,去研究学习,才能不断提高. 理论和实际是有关系的,一些题目也都有现实意义.计算机的一些模拟操作,通过数学算法,能够大大减轻代码量和算法复杂度. 第一题是机器人在坐标系上直走和转弯,通过简单的模拟就能实现.但是仔细思考发现还能通过线性代数,坐标变换的方式做,这样在实际中计算更快.甚至还可以用复数来做. 实际扫地机器人可能就用到了类似的算法.让他能够…
1041. 困于环中的机器人 题库链接: 1041. 困于环中的机器人. 题干 在无限的平面上,机器人最初位于 (0, 0) 处,面朝北方.机器人可以接受下列三条指令之一: "G":直走 1 个单位 "L":左转 90 度 "R":右转 90 度 机器人按顺序执行指令 instructions,并一直重复它们. 只有在平面中存在环使得机器人永远无法离开时,返回 true.否则,返回 false. 示例 示例 1 输入:"GGLLGG&q…
Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place. The move sequence is represented by a string. And each move is represent by a characte…
原题链接在这里:https://leetcode.com/problems/judge-route-circle/description/ 题目: Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place. The move seq…
Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place. The move sequence is represented by a string. And each move is represent by a characte…
645. Set Mismatch The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of the numbers in the set got duplicated to another number in the set, which results in repetition of one number and loss of another nu…
2017/11/3 Leetcode 日记 654. Maximum Binary Tree Given an integer array with no duplicates. A maximum tree building on this array is defined as follow: The root is the maximum number in the array.(根节点是数组中的最大值) The left subtree is the maximum tree const…
1. Two Sum Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution. Example: Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + n…
Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place. The move sequence is represented by a string. And each move is represent by a characte…
Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place. The move sequence is represented by a string. And each move is represent by a characte…
1.题目描述 Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place. The move sequence is represented by a string. And each move is represent by a c…
[抄题]: Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place. The move sequence is represented by a string. And each move is represent by a ch…
657. Judge Route Circle[easy] Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place. The move sequence is represented by a string. And each m…
344. Reverse String Write a function that takes a string as input and returns the string reversed. Example:Given s = "hello", return "olleh". class Solution(object): def reverseString(self, s): """ :type s: str :rtype: s…
Cleaner RobotCrawling in process... Crawling failed Time Limit:2000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u Submit Status Description   Input   Output   Sample Input   Sample Output   Hint   Description Masha has recently bought…
放假的时间已经过去一半了,每天坚持看一个多小时的书,时间虽然不多,但是能专心把书看进去就可以了.今天分享的是 LeetCode 上面的第 657 题,题目是<机器人能否返回原点>,这也是一道简单的题. LeetCode 题库的第 657 题——机器人能否返回原点 题的解法也很简单,先定义坐标,并设置坐标为(0, 0),然后按照给定的方向去移动,在移动的过程中修改方向,移动完以后再次判断坐标是否为(0, 0)即可.代码如下: bool judgeCircle(char* moves) { ; ;…
Leetcode不同路径系列题解笔记 62. 不同路径 一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为 "Start" ). 机器人每次只能向下或者向右移动一步.机器人试图达到网格的右下角(在下图中标记为 "Finish" ).问总共有多少条不同的路径? 两种解法:1. 简单的动态规划   2.计算组合值 (总共可以走m+n-2步,向下走需要选择n-1步) class Solution: def uniquePaths(self, m: int…