Skip to content

Instantly share code, notes, and snippets.

@freelze
Created September 27, 2017 17:09
Show Gist options
  • Save freelze/dac5121556392de8be793ca66735d6fa to your computer and use it in GitHub Desktop.
Save freelze/dac5121556392de8be793ca66735d6fa to your computer and use it in GitHub Desktop.
Runtime: 19 ms , Your runtime beats 41.75 % of cpp submissions.
class Solution
{
public:
bool judgeCircle(string moves)
{
int ud = 0 , lr = 0;
for(int i = 0; i < moves.length(); i++)
{
switch(moves[i])
{
case('U'):
++ud;
break;
case('D'):
--ud;
break;
case('L'):
--lr;
break;
case('R'):
++lr;
break;
default:
//return -1;
break;
}
}
if(ud == 0 && lr == 0) return true;
else return false;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment