#include<iostream> #include<string> using namespace std; class Solution { public: bool judgeCircle(string moves) { int X=0,Y=0; for(auto c:moves) { switch(c) { case 'U': X+=1; break; case 'D': X-=1; break; case 'L': Y+=1; break; case 'R': Y-=1; break; default: break; } } if(X==0 && Y==0) return true; else return false; } }; int main() { Solution s; string str; str = "UUDD"; if(s.judgeCircle(str)) cout<<"TRUE"<<endl; else cout<<"false"<<endl; return 0; }
