The move sequence is represented by a string. And each move is represent by a character. The valid robot moves are
Example 1:
Input: "UD" Output: true
Example 2:
Input: "LL" Output: false
//JAVA
class Solution {
public boolean judgeCircle(String moves) {
char [] words=moves.toCharArray(); //tansfer string to char[]
int x=0,y=0;
int len=moves.length();
int i=0;
for(i=0;i<len;i++)
{
if(words[i]=='U')
y++;
else
if(words[i]=='D')
y--;
else
if(words[i]=='R')
x++;
else
if(words[i]=='L')
x--;
}
if(x==0&&y==0)
return true;
else
return false;
}
}