leetcode657 C++ 16ms 判断回环

class Solution {
public:
    bool judgeCircle(string moves) {
        int x = 0;
        int y = 0;
        for(auto c:moves){
            if(c=='U'){
                y++;
            }
            else if(c=='D'){
                y--;
            }
            else if(c=='R'){
                x++;
            }
            else if (c=='L'){
                x--;
            }
        }
        return (x==0 && y==0);
    }
};

原文地址:https://www.cnblogs.com/theodoric008/p/9370942.html