Judge Route Circle


  • 0
    P
        var mvs = moves.split("");
        var temp1 = 0;
        var temp2 = 0;
        
        for(var i=0; i<mvs.length; i++) {
            if(mvs[i] == 'L') {
                temp1 -= 1;
            } else if(mvs[i] == 'R') {
                temp1 += 1;
            } else if(mvs[i] == 'U') {
                temp2 += 1;
            } else if(mvs[i] == 'D') {
                temp2 -= 1;
            }
        }
        
        if(temp1 == 0 && temp2 == 0) {
            return true;
        } else {
            return false;
        }
    };```

Log in to reply
 

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