Super Clean JAVA AC Code


  • 0
    W
        public boolean judgeCircle(String moves) {
            int u = 0;
            int r = 0;
            for (char c : moves.toCharArray()) {
                switch (c) {
                    case 'U':
                        u++;
                        break;
                    case 'D':
                        u--;
                        break;
                    case 'L':
                        r--;
                        break;
                    case 'R':
                        r++;
                        break;
                    default:
                        break;
                }
            }
            return Math.abs(u) + Math.abs(r) == 0;
        }
    
    

Log in to reply
 

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