[抄题]:

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

[暴力解法]:存count[4]数组中

时间分析:

空间分析:n

[优化后]:因为判断抵消效应,只用一个变量++--足矣

时间分析:

空间分析:1

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

转化成字符串数组后再操作

[一句话思路]:

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

判断抵消效应只用一个变量就行了

[复杂度]:Time complexity: O(n) Space complexity: O(1)

[英文数据结构或算法,为什么不用别的数据结构或算法]:

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

[代码风格] :

class Solution {
public boolean judgeCircle(String moves) {
//cc
if (moves == null) {
return false;
}
//array
int x = 0, y = 0;
for (char c : moves.toCharArray()) {
if (c == 'R') {
x++;
}
if (c == 'L') {
x--;
}
if (c == 'U') {
y++;
}
if (c == 'D') {
y--;
}
}
//return x && y
return (x == 0 && y == 0);
}
}

657. Judge Route Circle机器人能否返回的更多相关文章

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

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

  2. 657. Judge Route Circle【easy】

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

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

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

  4. 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 ...

  5. 657. Judge Route Circle

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

  6. Judge Route Circle

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

  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] Judge Route Circle 判断路线绕圈

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

  9. LeetCode Judge Route Circle

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

随机推荐

  1. Apache + Tomcat + 连接器JK

    一 安装Apache 下载apache: https://www.apache.org/   ->  http://mirrors.cnnic.cn/apache/  -> http:// ...

  2. RK3288 USB UVC camera 摄像头 VIDIOC_DQBUF Failed!!! err[I/O error]

    RK3288     Android5.1   多个品牌USB摄像头 同一块主板和代码,大部分品牌的USB摄像头可以正常使用,只有某一款USB摄像头不能使用. 插上摄像头,底层可以识别到摄像头. &l ...

  3. Java语言与C语言混合编程(1)--Java native 关键字

    一. 什么是 native Method 简单地讲,一个 native Method 就是一个java调用非java代码的接口.一个 native Method 是这样一个java的方法:该方法的实现 ...

  4. (转)Inno Setup入门(十六)——Inno Setup类参考(2)

    本文转载自:http://blog.csdn.net/yushanddddfenghailin/article/details/17250967 这里将接着在前面的基础上介绍如何在自定义页面上添加按钮 ...

  5. Vue踩坑记录册

    1.vue-cli+webpack项目 修改项目名称 解决办法: 1 删除 node_modules 文件夹(如果修改项目名称,需要在在package.json中修改对应的name) 2 重新安装依赖 ...

  6. 编写hibernateDao,使dao层都实现hibernateDao

    package com.wiseweb.core.dao; import java.io.Serializable; import java.util.ArrayList; import java.u ...

  7. 第十一章 Helm-kubernetes的包管理器(中)

    11.5 chart详解 chart由一系列文件组成,这些文件描述了K8s部署应用时需要的资源,比如Servcie.Deployment.PersistentVolmeClaim.Secret.Con ...

  8. canvas之画一条线段

    var canvas=document.getElementById("canvas"); //设置绘图环境 var cxt=canvas.getContext('2d'); // ...

  9. mongodb的安装(linux下)

    1.去官网下载安装包 2.解压tar包 tar -zxvf filename 3.移动路径,并进入路径 mv mongodb-linux-x86_64-3.0.6/ /usr/local/mongod ...

  10. http协议及web框架

    http协议简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于万维网(WWW:World Wide Web )服务器与本地浏览器之间传输超文本 ...