Swift solution


  • 0
    Z
    class Solution {
        func judgeCircle(_ moves: String) -> Bool {
            var route: (x: Int, y: Int) = (0, 0)
            moves.characters.map{
                if $0 == "U" {
                    route.y += 1
                } else if $0 == "D" {
                    route.y -= 1
                } else if $0 == "L" {
                    route.x -= 1
                } else if $0 == "R" {
                    route.x += 1
                }
            }
            
            return route == (0, 0)
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.