JavaScript use 'one variables' Solution


  • 0
    /**
     * @param {string} moves
     * @return {boolean}
     */
    var judgeCircle = function(moves) {
        var p = 0;
        for(let i=0;i<moves.length;i++){
            switch(moves[i]){
                case 'U':
                    p += 10;
                    break;
                case 'D':
                    p -= 10;
                    break;
                case 'L':
                    p += 1;
                    break;
                case 'R':
                    p -= 1;
                    break;
            }
        }
        return p ? false : true;
    };
    

Log in to reply
 

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