Simple Javascript solution


  • 0
    K

    var judgeCircle = function(moves) {

    var steps = {
        "U" : 2,
        "D" : -2,
        "R" : 1,
        "L" : -1
    }
    
    var result = 0;
    
    for(var i= 0; i < moves.length; i++){
        
        result += parseInt(steps[moves[i]]);    
        
    }
    
    return result === 0;
    

    };


Log in to reply
 

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