class Solution {
public boolean judgeCircle(String moves) {
int ud = 0;
int lr = 0;
for(int i = 0;i < moves.length();i++){
if(moves.charAt(i)=='U'){
ud+=1;
}else if(moves.charAt(i)=='D'){
ud-=1;
}else if(moves.charAt(i)=='L'){
lr+=1;
}else{
lr-=1;
}
}
if(ud==0&&lr==0){
return true;
}else{
return false;
}
}
}
One Leetcode per day-657. Can the robot return to the origin?
Guess you like
Origin blog.csdn.net/weixin_41041275/article/details/112425345
Recommended
Ranking