Concise Java Solution(comparing U with D and L with R)

  • 0
    class Solution {
        public boolean judgeCircle(String moves) {
            int[] dirs = new int[4];
            int len = moves.length();
            for(int i=0;i<len;++i){
                    case 'U': dirs[0] += 1;break;
                    case 'D': dirs[1] += 1;break;
                    case 'L': dirs[2] += 1;break;
                    case 'R': dirs[3] += 1;break;
                    default: return false;
            return dirs[0] == dirs[1] && dirs[2] == dirs[3];

Log in to reply

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