simple


  • 0
    V
    public bool JudgeCircle(string moves) {
            if(moves == null || moves.Length == 0) return true;
            int ci = 0; int cj = 0;
            for(int i = 0; i<moves.Length;i++){
                if(moves[i] == 'U') ci-=1;
                else if(moves[i] == 'L') cj-=1;
                else if(moves[i] == 'D') ci+=1;
                else cj+=1;
            }
            return ci==0 && cj ==0;
        }
    

Log in to reply
 

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