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

 

posted @ 2020-09-07 13:32  温暖了寂寞  阅读(154)  评论(0)    收藏  举报