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;
    }
}

 

posted on 2018-09-26 19:03  Sempron2800+  阅读(91)  评论(0编辑  收藏  举报