https://leetcode.com/problems/judge-route-circle/description/
bool judgeCircle(string moves) {
int h=0, v=0;
for(int i=0;i<moves.size();i++) {
switch (moves[i]) {
case 'R': h++; break;
case 'L': h--; break;
case 'U': v++; break;
case 'D': v--; break;
}
}
return h==0 && v==0;
}
No comments:
Post a Comment