Java Script Solution


  • 0
    B
    var judgeCircle = function(moves) {
        let x=0,y=0;
        for(let i = 0;i<moves.length;i++){
            switch (moves[i]) {
                case 'L': --x
                    break;
                case 'R': ++x
                    break;
                case 'U': ++y
                    break;
                case 'D': --y
                    break;
            }
        }
        if(x === 0 && y===0)
            return true;
        return false;
    };
    

Log in to reply
 

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