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

posted @ 2018-07-26 11:55  一条图图犬  阅读(220)  评论(0编辑  收藏  举报