C solution


  • 0
    S

    bool judgeCircle(char* moves) {
    int u = 0, l = 0;
    while(*moves!='\0')
    {
    switch(*moves)
    {
    case 'U':
    u++;
    break;
    case 'D':
    u--;
    break;
    case 'L':
    l++;
    break;
    case 'R':
    l--;
    break;
    default:
    break;
    }
    moves++;
    }
    if (u==0&&l==0)
    {
    return true;
    }else{
    return false;
    }
    }


Log in to reply
 

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