657. 机器人能否返回原点
题目链接:657. 机器人能否返回原点
代码如下:
class Solution
{
public:
bool judgeCircle(string moves)
{
int x=0,y=0;
for(int i=0;i<moves.size();i++)
{
if(moves[i]=='U') y--;
if(moves[i]=='D') y++;
if(moves[i]=='L') x--;
if(moves[i]=='R') x++;
}
if(x==0&&y==0) return true;
return false;
}
};