LeetCode 657. Judge Route Circle
Posted 几米空间
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
题目标签:String
距离上一次刷题已经是一个月之前了- -,因为终于找到了工作。上班一个月的感受是,练好英语很重要,比起写代码水平,首先你得把开会说的那些都听懂是吧。所以大家要把对英语的重视程度提高到和刷题一样!!!
Java Solution:
Runtime beats 72.84%
完成日期:03/24/2018
关键词:坐标
关键点:出发点为 x = 0, y = 0
1 class Solution 2 { 3 public boolean judgeCircle(String moves) 4 { 5 int x = 0; 6 int y = 0; 7 8 for(char c: moves.toCharArray()) 9 { 10 switch(c) 11 { 12 case \'R\': 13 x++; 14 break; 15 case \'L\': 16 x--; 17 break; 18 case \'U\': 19 y++; 20 break; 21 case \'D\': 22 y--; 23 break; 24 default: 25 System.out.println("Invalid move"); 26 } 27 } 28 29 30 return (x == 0 && y == 0); 31 } 32 }
参考资料:n/a
LeetCode 题目列表 - LeetCode Questions List
题目来源:https://leetcode.com/
以上是关于LeetCode 657. Judge Route Circle的主要内容,如果未能解决你的问题,请参考以下文章
[leetcode-657-Judge Route Circle]
LeetCode 657. Judge Route Circle
LeetCode 657. Judge Route Circle
leetcode-657-Judge Route Circle