Leetcode657. Judge Route Circle

来源:互联网 发布:淘宝买家怎么提升等级 编辑:程序博客网 时间:2024/06/16 17:53

一直刷水题,从未进步过。

class Solution {public:    bool judgeCircle(string moves) {        int x=0,y=0;        for(int i=0;i<moves.size();i++)        {            if(moves[i]=='L'){                x-=1;            }             if(moves[i]=='R'){                x+=1;            }             if(moves[i]=='U'){                y+=1;            }             if(moves[i]=='D'){                y-=1;            }        }        if(x==0&&y==0)return true;        else return false;    }};


原创粉丝点击