LeetCode 答案(Easy)(601-700)
来源:互联网 发布:在哪里注册域名便宜 编辑:程序博客网 时间:2024/04/27 23:41
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.
一开始,机器人位于(0,0)。输入一串移动次序命令,判断机器人是否走了一个圈,也就是说它是否回到了原点。
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.
移动顺序是一串字符串。每一步移动命令都是一个字符。有效的移动命令包括 R(向右) ,L(向左),U(向上)以及D(向下)。最终的输出是true或者false,同来表示机器人是否走了一个圈。
Example 1:Input: "UD"Output: true
Example 2:Input: "LL"Output: false
- 答案
public class Solution { public boolean judgeCircle(String moves) { // x轴坐标 int x = 0; // y轴坐标 int y = 0; for (int j = 0, length = moves.length(); j < length; j++) { if (moves.charAt(j) == 'R') { x++; } if (moves.charAt(j) == 'L') { x--; } if (moves.charAt(j) == 'U') { y++; } if (moves.charAt(j) == 'D') { y--; } } // System.out.println("机器人当前的坐标是:("+x+","+y+")"); return (x==0&&y==0); }}
阅读全文
0 0
- LeetCode 答案(Easy)(601-700)
- LeetCode 答案(Easy)(1-100)
- LeetCode 答案(Easy)(201-300)
- LeetCode 答案(Easy)(101-200)
- leetcode easy
- LeetCode--easy
- leetcode之旅-easy(House Robber)
- <LeetCode><Easy>242Valid Anagram (排序)
- 【leetcode】Array——easy(java)
- LeetCode 53. Maximum Subarray(Easy)
- 【一、Leetcode数组专题(1)easy】
- Leetcode[Easy] - Valid Palindrome
- Leetcode[Easy] - Path Sum
- Leetcode[Easy] - Two Sum
- Leetcode[easy] - Implement strStr()
- Leetcode--easy系列1
- Leetcode--easy系列2
- Leetcode--easy系列3
- Android OTA升级(二)之ota_from_target_files文件分析
- Spring Boot入门,一步一步简化,实现Spring Web项目开发
- iOS枚举的运用
- Go切片≠动态数组
- java 控制台打印圆形
- LeetCode 答案(Easy)(601-700)
- Android-PickerView系列之封装篇(三)
- Java ArrayList集合常用方法
- ToolBar和ActionBar右边三个点的图标替换
- 指针
- 获取用户手机IP的两种方式
- linux下wait命令的使用小结
- [python]Scatter 散点图例子
- 创建Java对象的五种方式以及JVM对字符串处理