LeetCode - 657. Judge Route Circle
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
public class Solution {
public boolean judgeCircle(String moves) {
if (moves == null)
return true;
int x = 0, y = 0;
for (int i=0; i<moves.length(); i++) {
char ch = moves.charAt(i);
if (ch == 'U')
y ++;
else if (ch == 'D')
y --;
else if (ch == 'L')
x --;
else if (ch == 'R')
x ++;
}
return x==0 && y==0;
}
}
LeetCode - 657. Judge Route Circle的更多相关文章
- Leetcode#657. Judge Route Circle(判断路线成圈)
题目描述 初始位置 (0, 0) 处有一个机器人.给出它的一系列动作,判断这个机器人的移动路线是否形成一个圆圈,换言之就是判断它是否会移回到原来的位置. 移动顺序由一个字符串表示.每一个动作都是由一个 ...
- 【LeetCode】657. Judge Route Circle 解题报告
[LeetCode]657. Judge Route Circle 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/judge-route- ...
- 657. Judge Route Circle【easy】
657. Judge Route Circle[easy] Initially, there is a Robot at position (0, 0). Given a sequence of it ...
- 657. Judge Route Circle机器人能否返回
[抄题]: Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this r ...
- 657. Judge Route Circle
static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...
- [LeetCode] Judge Route Circle 判断路线绕圈
Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot m ...
- LeetCode Judge Route Circle
原题链接在这里:https://leetcode.com/problems/judge-route-circle/description/ 题目: Initially, there is a Robo ...
- Judge Route Circle
Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot m ...
- Judge Route Circle --判断圆路线
Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot m ...
随机推荐
- JAVA WEB之Spring4.x JdbcTemplate
jdbcTemplate 说白了,他就是Spring提供用于简化数据库访问的类 基本jdbc驱动访问数据库 /* 一个简易好用的数据库连接和访问类 */ package cslg.cn.control ...
- ios开发 第三天
1.复合 对象可以引用其它对象,可以利用其它对象提供的特性. 通过包含作为实例变量的对象指针实现的. 2.OC是单一继承 3.继承-重构 4.类实例化对象时,self指向了对象的首地址. 类对象isa ...
- Thrift compiler代码生成类解析
代码生成类解析: Thrift--facebook RPC框架,介绍就不说了,百度,google一大把,使用也不介绍,直接上结构和分析吧. Hello.thrift文件内容如下: namespace ...
- 【原创】区分png图片格式和apng图片格式的解决办法
最近公司有个项目,要抓取客户微信公众号的文章,以及文章内容中的图片,并且在图片加上客户自己的水印.我们使用阿里云OSS存储图片和加水印,发现真心好用,提升了我们的开发效率,阿里云现在是越来越强大了.. ...
- RocketMQ-quickstart(批量消费问题)
基本概念: Producer:消息生产者,负责生产消息,一般由业务系统负责生产消息. Consumer:消息消费者,负责消费消息,一般是后台系统负责异步消费. Push Consumer:Consum ...
- 浅谈Android进阶之路
过去十年是移动互联网蓬勃发展的黄金期,相信每个人也都享受到了移动互联网红利,在此期间,移动互联网经历了曙光期.成长期.成熟期.现在来说已经进入饱和期.依然记得在 2010-2013 年期间,从事移动开 ...
- js_8_dom标签
创:9_3_2017 星期4 修: 对于在a标签中,如何阻止跳转? 定义一个事件,事件顺序执行后才执行跳转,如果事件函数返回false,则后面事件就不触发 事件1 = "return 函数 ...
- linkinFrame--测试项目添加git管理
OK,前面一篇博客,已经搭建好了项目的基础的结构.现在我们添加一个简单的servlet来测试下项目能不能跑,然后在讲项目添加到coding上用git管理. 1,我们编写一个servlet,编写一个js ...
- linux指令--ls
本篇博客转自http://www.cnblogs.com/peida/archive/2012/10/23/2734829.html,在原作者基础上做了修改和总结. ls命令是linux下最常用的命令 ...
- webpack + vue
开始之前 本文包含以下技术,文中尽量给与详细的描述,并且附上参考链接,读者可以深入学习: 1.webpack2.Vue.js3.npm4.ES6语法 前言 在对着产品高举中指怒发心中之愤后,真正能够解 ...