LeetCode657 Robot Return to Origin

文章目录
  1. 1. 题目
  2. 2. 思路
  3. 3. 代码

题目

LeetCode657 Robot Return to Origin

思路

判断上和下,左和右的次数是否相同即可.

代码

1
2
3
4
5
6
7
8
class Solution {
public:
bool judgeCircle(string moves) {
unordered_map<char, int> f;
for (auto& c: moves) f[c]++;
return f['U'] == f['D'] && f['L'] == f['R'];
}
};
分享到 评论