C# answer.


  • 0
    S
    public bool JudgeCircle(string moves) {
            if (moves == null || moves == "")
                {
                    return true;
                }
    
                // Keeps numbers of R/L/U/D in this order.
                int[] numberOfValues = new int[4];
    
                for (int i = 0; i < moves.Length; i++)
                {
                    if (moves[i] == 'R')
                    {
                        numberOfValues[0]++;
                    }
                    else if (moves[i] == 'L') {
                        numberOfValues[1]++;
                    }
                    else if (moves[i] == 'U') {
                        numberOfValues[2]++;
                    }
                    else {
                        numberOfValues[3]++;
                    }
                }
                         
                return numberOfValues[0] == numberOfValues[1] && 
    numberOfValues[2] == numberOfValues[3];
            
        }
    

Log in to reply
 

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