Skip to content

Commit 694d641

Browse files
Create robot_return_to_origin.cpp
1 parent 796a003 commit 694d641

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

robot_return_to_origin.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public:
3+
bool judgeCircle(string moves) {
4+
int r = 0, c = 0;
5+
6+
for(auto &move : moves) {
7+
if(move == 'U') r--;
8+
else if(move == 'D') r++;
9+
else if(move == 'L') c--;
10+
else c++;
11+
}
12+
return r == 0 and c == 0;
13+
}
14+
};

0 commit comments

Comments
 (0)