leetcode657

bool judgeCircle(string moves) {
    int V = 0;//垂直位移
    int H = 0;//水平位移
    for (auto m : moves)
    {
        if (m == 'U')
        {
            V++;
        }
        else if (m == 'D')
        {
            V--;
        }
        else if (m == 'L')
        {
            H--;
        }
        else if (m == 'R')
        {
            H++;
        }        
    }
    if (V == 0 && H == 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}
原文地址:https://www.cnblogs.com/asenyang/p/9708934.html