Java 14ms simple solution


  • 0
    G

    class Solution {
    public boolean judgeCircle(String moves) {
    int vertical =0;
    int lateral = 0;

        for(char ch : moves.toCharArray()){
            if (ch == 'U')
                vertical++;
            else if (ch == 'D')
                vertical--;
            else if( ch== 'L')
                lateral--;
            else 
                lateral++;
        }
        return vertical + lateral == 0;
    }
    

    }


Log in to reply
 

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