LeetCode #657. Robot Return to Origin 机器人能否返回原点
https://leetcode-cn.com/problems/robot-return-to-origin/
设置 flagUD 记录机器人相对于原点在纵向上的最终位置
flagRL 记录机器人相对于原点在横向上的最终位置
如果最终 flagUD==0 && flagRL==0 ,说明机器人的最终位置与原点相同
class Solution {
public boolean judgeCircle(String moves) {
int flagRL = 0;
int flagUD = 0;
char[] move = moves.toCharArray();
for (int i = 0; i < move.length; i++ ) {
switch (move[i]) {
case 'L':
flagRL ++;
break;
case 'R':
flagRL --;
break;
case 'U':
flagUD ++;
break;
case 'D':
flagUD --;
break;
}
}
if (flagRL == 0 && flagUD == 0) {
return true;
} else {
return false;
}
}
}
LeetCode #657. Robot Return to Origin 机器人能否返回原点的更多相关文章
- Leetcode657.Robot Return to Origin机器人能否返回原点
在二维平面上,有一个机器人从原点 (0, 0) 开始.给出它的移动顺序,判断这个机器人在完成移动后是否在 (0, 0) 处结束. 移动顺序由字符串表示.字符 move[i] 表示其第 i 次移动.机器 ...
- LeetCode 657 Robot Return to Origin 解题报告
题目要求 There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of it ...
- LeetCode 657. Robot Return to Origin (C++)
题目: There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its ...
- LeetCode 657. Robot Return to Origin
There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its mov ...
- 【leetcode】657. Robot Return to Origin
Algorithm [leetcode]657. Robot Return to Origin https://leetcode.com/problems/robot-return-to-origin ...
- 【Leetcode_easy】657. Robot Return to Origin
problem 657. Robot Return to Origin 题意: solution1: class Solution { public: bool judgeCircle(string ...
- 【LeetCode】657. Robot Return to Origin 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 复数求和 counter统计次数 相似题目 参考资料 ...
- 657. Robot Return to Origin
Description There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequenc ...
- LeetCode--Squares of a Sorted Array && Robot Return to Origin (Easy)
977. Squares of a Sorted Array (Easy)# Given an array of integers A sorted in non-decreasing order, ...
随机推荐
- [书接上一回]在Oracle Enterprise Linux (v5.7) 中安装DB - (2/4)
在最后一行,书写shmfs /dev/shm tmpfs size=2g 0 用来调高数据库运行是的内存分配问题. 创建需要的路径和分配权限. 设置 oracle 用户环境参数. 修改标头显示的部分. ...
- GitHub 搭建博客,出现 hexo g -d 报错
想搭建一个个人博客,但是在将博客推送到Github上的时候在git bash 下运行hexo g -d命令出现错误: 错误如下: fatal: HttpRequestException encoun ...
- Perl脚本通过Expect登陆多台设备批量执行命令并Log
本例子尝试使用Perl脚本借助Expect模块实现如下目的: 登陆多台设备 设备登陆信息按如下格式存放于文件中. $ cat hosts.txt 192.168.30.7:node1:telnet:b ...
- [Poj2349]Arctic Network(二分,最小生成树)
[Poj2349]Arctic Network Description 国防部(DND)要用无线网络连接北部几个哨所.两种不同的通信技术被用于建立网络:每一个哨所有一个无线电收发器,一些哨所将有一个卫 ...
- uboot学习之五-----uboot如何启动Linux内核
uboot和内核到底是什么?uboot实质就是一个复杂的裸机程序:uboot可以被配置也可以做移植: 操作系统内核本身就是一个裸机程序,和我们学的uboot和其他裸机程序没有本质的区别:区别就是我们操 ...
- alert(1) to win 2
function escape(s) { s = s.replace(/"/g, '\\"'); return '<script>console.log("' ...
- jmeter性能工具 之 cookie 管理器 (二)
上一篇主要介绍了jmeter 的基本使用方法,编写了登陆脚本,这一篇在登陆基础上,进行充值操作. 问:什么时候需要用到cookied 管理器? 答:需要登陆信息时,如果充值,提现,淘宝的下单,添加到购 ...
- 【leetcode】1030. Matrix Cells in Distance Order
题目如下: We are given a matrix with R rows and C columns has cells with integer coordinates (r, c), whe ...
- 对webpack的初步研究2
Entry Points 如“ 入门”中所述,有多种方法可以entry在webpack配置中定义属性.我们会告诉你,你的方法可以配置的entry属性,除了解释为什么它可能对你有用 Single Ent ...
- 如何在mac上使用iMessage发送信息
在Mac上你也可以像iPhone上一样使用iMessage 来发送iMessage 与 普通的短信息. 并且你需要在iPhone上设置中的信息的信息转发中激活对电脑的支持.此时, 你的电脑也可以向你的 ...