C++ Solution


  • 1
    D
    class Solution {
    public:
        bool judgeCircle(string moves) {
            int pos = 0;
            
            for(auto c : moves) {
                if (c == 'U' || c == 'R')
                    pos++;
                else
                    pos--;
            }
            
            return (pos == 0);
        }
    };
    

    Technically, finishing at the same position where you started means there are an equal number of movements in the opposite direction.


  • 0
    J

    @darwin67 I don't think that this would work because 'UUULLL' would return true, even though the robot would be at position (-3, 3). For my solution I kept a separate variable for x and y position, finally checking if both xPos and yPos are 0


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.