【leetcode】机器人能否返回原点

.

bool judgeCircle(char * moves){
    int n = strlen(moves),int count1=0,count2=0;
    for (int i=0; i<n; i++)
    {
        if (moves[i] == 'U') count1++;
        else if (moves[i] == 'D') count1--;
        else if (moves[i] == 'R') count2++;
        else count2--;
    }
    return !count1 && !count2;
}
原文地址:https://www.cnblogs.com/ganxiang/p/13626351.html