Solution--Java


  • 0
    N
    class Solution {
        public boolean judgeCircle(String moves) {
            int ver = 0, hor = 0;
            for (int i = 0; i < moves.length(); i++) {
                switch (moves.charAt(i)) {
                    case 'L':
                        hor++;
                        break;
                    case 'R':
                        hor--;
                        break;
                    case 'U':
                        ver++;
                        break;
                    case 'D':
                        ver--;
                        break;
                }
            }
            return hor == 0 && ver == 0 ? true: false;
        
        }
    }
    

Log in to reply
 

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