Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func judgeCircle(moves string) bool {
- xCount , yCount := 0 , 0
- countRange := func(moveOp byte){
- switch moveOp {
- case 'L':
- xCount++
- case 'R':
- xCount--
- case 'U':
- yCount++
- case 'D':
- yCount--
- }
- }
- moveCount := len(moves)
- halfMoveCount := moveCount / 2
- for i:=0 ; i < halfMoveCount ; i++{
- countRange(moves[i])
- countRange(moves[moveCount - 1 - i])
- }
- if(halfMoveCount * 2 != moveCount){
- countRange(moves[halfMoveCount])
- }
- return xCount==0 && yCount==0;
- }
Add Comment
Please, Sign In to add comment