Judge Route Circle - Java Solution


  • 0
    S
    class Solution {
        public boolean judgeCircle(String moves) {
            int[] currPos = {0,0};
            char[] dir = moves.toCharArray();
            for (char d : dir)
            switch (d) {
                case 'U':
                    currPos[1]++;
                    break;
                case 'D':
                    currPos[1]--;
                    break;
                case 'L':
                    currPos[0]--;
                    break;
                case 'R':
                    currPos[0]++;
                    break;
                default:
                    break;
            }
            if (currPos[0] == 0 && currPos[1] ==0) {
                return true;
            }
            return false;
        }
    }
    

Log in to reply
 

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