Simple Java Solution 12ms


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