C++ Solution


  • 0
    Y

    In order to return to the original point, the number of 'U' and 'D' must be the same, and the number of 'R' and 'L' must be the same.

    class Solution {
    public:
        bool judgeCircle(string moves) {
            
            map<char, int> m;
            for (char c : moves) {
                if (m.find(c) == m.end()) {
                    m.insert(pair<char, int>(c, 1));
                }
                else {
                    m[c]++;
                }
            }
            return m['U'] == m['D'] && m['R'] == m['L'];
            
        }
    };
    

Log in to reply
 

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