Simple Java Solution


  • 0
    I
    public boolean judgeCircle(String moves) {
            
            int down =0;
            int up = 0;
            int right=0;
            int left=0;
            
            for(int i=0;i<moves.length();i++){
                if(moves.charAt(i)=='D'){
                    down++;
                } else if(moves.charAt(i)=='U'){
                    up++;
                } else if(moves.charAt(i)=='R'){
                    right++;
                } else {
                    left++;
                }
            }
            
            if(down-up==0 && right-left==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.