Skip to content

Instantly share code, notes, and snippets.

@tin80122
Created August 18, 2019 17:37
Show Gist options
  • Save tin80122/8b15e5ae521d8e44d16aa636a099a72c to your computer and use it in GitHub Desktop.
Save tin80122/8b15e5ae521d8e44d16aa636a099a72c to your computer and use it in GitHub Desktop.
/**
* @param {string} moves
* @return {boolean}
*/
var judgeCircle = function(moves) {
var x = 0 , y = 0;
var ary = moves.split('');
for(var i = 0; i< ary.length ; i++){
switch(ary[i]){
case 'R':
x += 1;
break;
case 'L':
x -= 1;
break;
case 'U':
y -= 1;
break;
case 'D':
y += 1;
break;
}
}
return (x == 0 && x === y) ? 1 : 0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment