Leetcode 657 Solution
This article provides solution to leetcode question 657 (robot-return-to-origin)
Access this page by simply typing in "lcs 657" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/robot-return-to-origin
Solution
class Solution {
public:
bool judgeCircle(string moves) {
int x = 0;
int y = 0;
for (auto it = moves.begin(); it != moves.end(); it++)
{
char ch = *it;
switch(ch)
{
case 'U': y -= 1; break;
case 'D': y += 1; break;
case 'L': x -= 1; break;
case 'R': x += 1; break;
}
}
return x == 0 && y == 0;
}
};