JavaScript Solution


  • 0
    F
    /**
     * @param {string} moves
     * @return {boolean}
     */
    var judgeCircle = function(moves) {
        var v = [0, 0];
        var i, len;
        
        for (i = 0, len = moves.length; i < len; i++) {
            var move = moves.charAt(i);
            switch (move) {
                case 'U':
                    v[1]++;
                    break;
                case 'D':
                    v[1]--;
                    break;
                case 'R':
                    v[0]++
                    break;
                case 'L':
                    v[0]--;
                    break;
                default:
                    break;
            }
        }
        
        return v[0] === 0 && v[1] === 0;
    };
    

Log in to reply
 

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