class Solution {
public:
bool judgeCircle(string moves) {
if(moves.size() % 2) return false;//移动次数为奇数
int num1 = 0, num2 = 0;
for(const auto &c : moves){
if(c == 'R') ++num1;
else if(c == 'L') --num1;
else if(c == 'U') ++num2;
else --num2;
}
return num1 == 0 && num2 == 0;
}
};
LeetCode第 657 题:机器人能否返回原点(C++)
最新推荐文章于 2024-10-17 19:06:39 发布