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 character. The valid robot moves are R (Right), L(Left), U (Up) and D (down). The output should be true or false representing whether the robot makes a circle.

Example 1:

Input: "UD"
Output: true

Example 2:

Input: "LL"
Output: false 思路:
    1.这是一个模拟横纵坐标移动的问题,向左移动x--,向右x++,向上y++,向下y--,最后判断 x == 0 && y == 0即可。
    2.直接判断'L','R','U','D'出现的次数是否相等
实现代码:
class Solution {
public:
bool judgeCircle(string moves) {
int x=,y=;
for (int i = ; i < moves.length(); i++){
if (moves[i] == 'L') x--;
else if (moves[i] == 'R') x++;
else if (moves[i] == 'U') y++;
else y--;
}
return x == && y == ;
}
};

Judge Route Circle --判断圆路线的更多相关文章

  1. [LeetCode] Judge Route Circle 判断路线绕圈

    Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot m ...

  2. Leetcode#657. Judge Route Circle(判断路线成圈)

    题目描述 初始位置 (0, 0) 处有一个机器人.给出它的一系列动作,判断这个机器人的移动路线是否形成一个圆圈,换言之就是判断它是否会移回到原来的位置. 移动顺序由一个字符串表示.每一个动作都是由一个 ...

  3. 【LeetCode】657. Judge Route Circle 解题报告

    [LeetCode]657. Judge Route Circle 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/judge-route- ...

  4. 657. Judge Route Circle【easy】

    657. Judge Route Circle[easy] Initially, there is a Robot at position (0, 0). Given a sequence of it ...

  5. 657. Judge Route Circle机器人能否返回

    [抄题]: Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this r ...

  6. LeetCode Judge Route Circle

    原题链接在这里:https://leetcode.com/problems/judge-route-circle/description/ 题目: Initially, there is a Robo ...

  7. Judge Route Circle

    Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot m ...

  8. LeetCode - 657. Judge Route Circle

    Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot m ...

  9. 657. Judge Route Circle

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...

随机推荐

  1. logback:logback和slf4j中的:appender、logger、encoder、layout

    (1)appender 1.appender标签是logback配置文件中重要的组件之一.在logback配置文件中使用appender标签进行定义.可 以包含0个或多个appender标签. 2.a ...

  2. Python 的笔试题

    其实大多数说学习Python 是纯兴趣,真的我不信,许多人已经工作了,没有那么多时间搞自己的纯兴趣了,都会为了生活奋斗,可以说转行来学python 就是未来加薪,当然,小编现在也快要准备工作了,所以也 ...

  3. HTTP第一篇

    为什么要学HTTP? 我们绝大多数的Web应用都是基于HTTP来进行开发的.我们对Web的操作都是通过HTTP协议来进行传输数据的. HTTP的诞生主要是为了能够让文档之间相互关联,形成超文本可以互相 ...

  4. JVM菜鸟进阶高手之路一(一次与笨神,阿飞近距离接触修改JVM)

    转载请注明原创出处,谢谢! 今天在JVMPocket群里面看见,阿牛发了一个gc截图,之后ak47截图了特别恐怖,我就觉得好奇,去看看服务情况,截图日志如下 关于jstat命令详情可以参考:https ...

  5. [转]Xcode的快捷键及代码格式化

    Xcode比较常用的快捷键,特别是红色标注的,很常用.1. 文件CMD + N: 新文件CMD + SHIFT + N: 新项目CMD + O: 打开CMD + S: 保存CMD+OPt+S:保存所有 ...

  6. filter的两种使用方法

    1. 在模板中使用filter 我们可以直接在{{}}中使用filter,跟在表达式后面用 | 分割,语法如下: {{ expression | filter }} 也可以多个filter连用,上一个 ...

  7. Java代理和动态代理

    code from <Thinking in java> 代理模式 interface Interface { void doSomething(); void somethingElse ...

  8. hadoop 基本命令

    hdfs相关 1.查看HDFS文件目录 hadoop fs -ls / mapreduce相关 1.查看mapred job mapred job -list hadoop job -list Use ...

  9. Linux入门之常用命令(9)进程及端口查看

    [Linux下查看进程] 查看程序对应进程号:ps –ef|grep 程序名 查看进程占用端口:ss -pl | grep 进程号 [通过进程查看端口] 查看占用的端口号:netstat –nltp| ...

  10. 模糊搜索神器fzf

    前言 fzf是目前最快的fuzzy finder.使用golang编写.结合其他工具(比如ag和fasd)可以完成非常多的工作. 让你通过输入模糊的关键词就可以定位文件或文件夹.当你的思维也习惯了模糊 ...