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;
}
}
}
每日一道Leetcode - 657. 机器人能否返回原点
猜你喜欢
转载自blog.csdn.net/weixin_41041275/article/details/112425345
今日推荐
周排行