Easy Java Solution


  • 0
    A
     public boolean judgeCircle(String moves) {
            int x = 0,y = 0;
            for(int i = 0;i < moves.length();i ++){
                char c = moves.charAt(i);
                switch (c){
                    case 'R':
                        x ++;
                        break;
                    case 'L':
                        x --;
                        break;
                    case 'U':
                        y ++;
                        break;
                    case 'D':
                        y --;
                        break;
                    default:
                        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.