Easy & clear solution


  • 0
    B

    I guess maybe this question is to check whether you are familar with switch in java.

            int pos = 0;
         
            for(char ch : moves.toCharArray()){
                switch(ch){
                    case 'U': pos += 1;
                            break;
                    case 'D': pos -= 1;
                            break;
                    case 'L': pos += 2;
                            break;
                    case 'R': pos -= 2;
                            break;
                }
            }
            return pos == 0;
        }

Log in to reply
 

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