题目地址:

https://www.lintcode.com/problem/judge-route-circle/description

在平面直角坐标系里,以方向给一个出发点在(0,0)(0,0)(0,0)的机器人发指令。问它的路径是否构成一个环。其实就是判断是否回到了原点。代码如下:

public class Solution {/*** @param moves: a sequence of its moves* @return: if this robot makes a circle*/public boolean judgeCircle(String moves) {// Write your code hereint U = 0, R = 0;for (int i = 0; i < moves.length(); i++) {char m = moves.charAt(i);if (m == 'U') {U++;} else if (m == 'D') {U--;} else if (m == 'R') {R++;} else {R--;}}return U == 0 && R == 0;}
}

时间复杂度O(n)O(n)O(n),空间O(1)O(1)O(1)。

【Lintcode】1104. Judge Route Circle相关推荐

  1. 【HDU】5343 MZL's Circle Zhou【后缀自动机】

    传送门:[HDU]5343 MZL's Circle Zhou 对于a串可能和b串重复的部分,我们总能找到一个位置,使得a串达到最长,即a串的后继为空,所以我们只要预处理以字符x为开头的b串的个数即可 ...

  2. 【HUSTOJ】Online Judge

    HUSTOJ Online Judge [环境] 操作系统:Ubuntu16 更换阿里云源 sudo cp /etc/apt/sources.list /etc/apt/sources.list.ba ...

  3. 【LintCode】算法题 1443. 最长AB子串

    描述 给你一个只由字母'A'和'B'组成的字符串s,找一个最长的子串,要求这个子串里面'A'和'B'的数目相等,输出该子串的长度. 这个子串可以为空. s的长度n满足 2<=n<=1000 ...

  4. 【lintcode】树形数据结构之Maxtree, Tree iterator, remove bst node, 优先队列之动态中位数Median, 矩阵dfs之word search II,最大连

    解析 max ksubarray sum:  最大和 of 连续子序列 =>   最大和 of  k份连续子序列 属于dp,30行代码搞定,注意一些边界. substr diff:  无queu ...

  5. LeetCode 657. Judge Route Circle

    题目: Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this rob ...

  6. [LeetCode]657.Judge Route Circle

    题目描述: Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this r ...

  7. 【项目】Online Judge(在线评判系统)

    Online Judge(在线评判系统) 文章目录 Online Judge(在线评判系统) 前言 一.Online Judge是什么? 二.通过这个项目能够学到什么? 1.C++ 2.网络编程 3. ...

  8. 【Lintcode】1413. Tree

    题目地址: https://www.lintcode.com/problem/tree/description 给定一个无向图,其有树性质,并且顶点编号为111的为树根(也就是这个图是个有根树).要求 ...

  9. 【Lintcode】1645. Least Subsequences

    题目地址: https://www.lintcode.com/problem/1645/ 给定一个长nnn的数组AAA,问AAA最少能分解为多少个严格递减的子序列之并. 在AAA上定义偏序关系< ...

最新文章

  1. HTML-加速、再加速
  2. 关于多人操作数据的处理策略
  3. mybatis-MyBatis-Plus
  4. MySQL 出现 The table is full 的解决方法
  5. 【BZOJ1188】分裂游戏(博弈论)
  6. Collections.min()和Collections.max()的使用
  7. sql express 无法启动服务_在Windows2012下安装SQL Server 2005无法启动服务的解决办法...
  8. 微信小程序 界面从右边滑出_微信小程序MUI侧滑导航菜单示例(Popup弹出式,左侧不动,右侧滑动)...
  9. Codeforces Round #205 (Div. 2) : D
  10. Java如何读指定行
  11. gin c.Next()方法
  12. FD.io VPP 20.09版本正式发布:往期VPP文章回顾+下载地址+相关链接
  13. HTML5与CSS3权威指南.pdf7
  14. vscode 搭建SSM项目环境
  15. Tableau可视化---Tableau简介
  16. C# 如何批量删除Excel单元格中的公式只保留数据
  17. Java 中status意思_struts的status属性
  18. 移动硬盘如何合并磁盘
  19. caj转word免费转换怎么操作?
  20. 码云上开源JAVA项目收藏

热门文章

  1. 智牛股_第4章_Nacos+Ceph分布式存储+Netty通讯
  2. Allegro PCB封装焊盘介绍(一)
  3. 目标检测论文解读复现【NO.21】基于改进YOLOv7的小目标检测
  4. 什么是swift闭包?
  5. 今日任务,摸鱼到下班
  6. 电子学会python三级笔记
  7. Laravel5常用命令行
  8. Selenium(二)_控件定位及简单操作
  9. Python基础——re表达式中re.sub()的用法
  10. oracle实例的内存(SGA和PGA)的调整和优化(转载)