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.


Log in to reply
 

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