java solution


  • 0
    C
    public boolean judgeCircle(String moves) {
            int x = 0;
            int y = 0;
            for (char c : moves.toCharArray()) {
                switch (c){
                    case 'L':
                        x--;
                        break;
                    case 'R':
                        x++;
                        break;
                    case 'U':
                        y++;
                        break;
                    case 'D':
                        y--;
                        break;
                }
            }
            return x == 0 && y == 0;
        }
    

Log in to reply
 

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