Easy to understand Java solution.


  • 0
    F
    class Solution {
        public boolean judgeCircle(String moves) {
            int x = 0, y = 0;
            for (char c : moves.toCharArray()) {
                if(c == 'U') {
                    x++;
                }else if(c == 'D') {
                    x--;
                }else if(c == 'L') {
                    y--;
                }else {
                    y++;
                }
            }
            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.