Skip to content

Latest commit

 

History

History
34 lines (34 loc) · 731 Bytes

0657 | 机器人能否返回原点.md

File metadata and controls

34 lines (34 loc) · 731 Bytes
class Solution {
public:
    bool judgeCircle(string moves) {
        int RL=0;
        int UD=0;
        string::iterator itr;
        for(itr=moves.begin(); itr!=moves.end(); itr++)
        {
            switch(*itr)
            {
                case 'R':
                    RL++;
                    break;
                case 'L':
                    RL--;
                    break;
                case 'U':
                    UD++;
                    break;
                case 'D':
                    UD--;
                    break;
                default:
                    ;
            }
        }
        if(RL==0 && UD==0)
            return true;
        else
            return false;
    }
};