C solution


  • 0
    G

    bool judgeCircle(char* moves)
    {
    int steps = strlen(moves);
    int x,y,s;

    x = y = s = 0;
    for( ; s<steps; ++s)
    {
        switch(moves[s])
        {
            case 'U':
                y ++;
                break;
            case 'D':
                y --;
                break;
            case 'L':
                x --;
                break;
            case 'R':
                x ++;
                break;
            default:
                break;
        }
    }
    if(x==0 && y==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.