Judge Route Circle --判断圆路线

时间:2022-09-16 16:18:27

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. &lbrack;LeetCode&rsqb; 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&num;657&period; Judge Route Circle(判断路线成圈)

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

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

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

  4. 657&period; 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&period; 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&period; 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&period; Judge Route Circle

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

随机推荐

  1. PYTHON isinstance语法

    def obj_len(arg): #isinstance(),判断是否是某一类 if isinstance(arg,str) or (isinstance(arg,list)) or (isinst ...

  2. 浪潮之巅IT那点事之三——神奇的规律

    “道可道,非常道”是老子在<道德经>中的开篇第一句话,这句话的意思是:万事万物其真理是可以探索并道说得出来的,但这些真理并非是永恒的,天道轮转,没有永恒不变的真理(来自百度百科).在IT行 ...

  3. Win7 &lowbar;Object&lowbar;header 中的 TypeIndex

    Win7 比较 xp下ObjectHeader中的内容有所变化,xp直接在OBJECT_HEADER里保存了POBJECT_TYPE指针,而Win7中把所有的对象类型放在了一个表里,这个表叫做ObTy ...

  4. centos6&period;5 apache&plus;tomcat结合 负载均衡

    一. 负载均衡:根据 uri 表达式把请求分发给各个服务器处理.如:/*.jsp = lb_s  就是说把所有jsp请求交给lb_s , 当然它是个Tomcat. 二. 安装配置mod_jk    m ...

  5. 实训第二天早上--hibernate之配置文件映射和注解

    hibernate 逐步优化第一步 只按照步骤来提取的jre包导入错误第二步 继续封装,把增删改查提取出来,同时进行代码的封装HQL语句  be stranger in the code .be fo ...

  6. codevs2492上帝造题的七分钟 2(线段树)

    /* 区间修改 区间查询 可以用线段树搞 但是一般的标记下放对这个题好像不合适 只能改叶子 然后更新父亲(虽然跑的有点慢) 小优化:如果某个点是1 就不用再开方了 所以搞一个f[i]标记 i 这个点还 ...

  7. 7&lowbar;Table Views

    7 // // ViewController.swift // Table Views // // Created by ZC on 16/1/9. // Copyright © 2016年 ZC. ...

  8. hdu4352(数位dp)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4352 题意:求区间L到R之间的数A满足A的的数位的最长递增序列的长度为K的数的个数. 分析:数位dp, ...

  9. C&num;引用C&plus;&plus;的DLL方案&lpar;C&num;调用非托管动态链接库&rpar;

    SocketClientInit是C++里面定义的方法,通过EntryPoint = "?SocketClientInit@@YAHHHPAD@Z"指出这个函数的真正入口处,方法是 ...

  10. C&num; 木马功能的简单实现

    1.首先解决开机启动木马.通过建立开机启动服务达到目的:2.伪装问题.通过c#反射性能,将正常的.net的exe文件添加监控盗传播取等其他功能,执行正常程序同时,后台悄悄释放windows服务,通过服 ...