[LeetCode]657. Judge Route Circle
题目描述
思路
水题 一次遍历
代码
#include <iostream>
#include <string>
using namespace std;
class Solution {
public:
bool judgeCircle(string moves) {
int row = 0,
col = 0;
for (char ch : moves) {
if (ch == 'U') row++;
if (ch == 'D') row--;
if (ch == 'L') col--;
if (ch == 'R') col++;
}
return row == 0 && col == 0;
}
};
int main() {
Solution s;
cout << s.judgeCircle("UD") << endl;
cout << s.judgeCircle("LL") << endl;
system("pause");
return 0;
}