Guest User

Untitled

a guest
Mar 17th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. func judgeCircle(moves string) bool {
  2. xCount , yCount := 0 , 0
  3. countRange := func(moveOp byte){
  4. switch moveOp {
  5. case 'L':
  6. xCount++
  7. case 'R':
  8. xCount--
  9. case 'U':
  10. yCount++
  11. case 'D':
  12. yCount--
  13. }
  14. }
  15.  
  16. moveCount := len(moves)
  17. halfMoveCount := moveCount / 2
  18. for i:=0 ; i < halfMoveCount ; i++{
  19. countRange(moves[i])
  20. countRange(moves[moveCount - 1 - i])
  21. }
  22. if(halfMoveCount * 2 != moveCount){
  23. countRange(moves[halfMoveCount])
  24. }
  25. return xCount==0 && yCount==0;
  26. }
Add Comment
Please, Sign In to add comment