solution,Just try this feature


  • 0
    5

    /**

    • @param {string} moves

    • @return {boolean}
      */
      var judgeCircle = function(moves) {
      var xDistance = 0;
      var yDistance = 0;

      var moveArray = moves.split("");
      for(let i=0;i<moveArray.length;i++){
      if(moveArray[i] == "U"){
      yDistance++;
      }
      if(moveArray[i] == "D"){
      yDistance--;
      }
      if(moveArray[i] == "R"){
      xDistance++;
      }
      if(moveArray[i] == "L"){
      xDistance--;
      }
      }
      return xDistance == 0 && yDistance == 0;
      };


Log in to reply
 

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