-
-
Save tin80122/8b15e5ae521d8e44d16aa636a099a72c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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