Java Solution

  • 0

    class Solution {
    public boolean judgeCircle(String moves) {
    //count Right is 0 Left is 1 UP is 2 Down is 3
    int []counts=new int[4];
    for(int i=0;i<moves.length();i++){
    char c=moves.charAt(i);
    if(c=='R') counts[0]++;
    else if(c=='L') counts[1]++;
    else if(c=='U') counts[2]++;
    else if(c=='D') counts[3]++;

        return ((counts[0]==counts[1])&&(counts[2]==counts[3]));


Log in to reply

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