simple scala solution


  • 0
    object Solution {
        def judgeCircle(moves: String): Boolean = {
            if (moves == null) false
            var x = 0
            var y = 0
            moves.map(c => c match {
                case 'U' => x = x + 1
                case 'D' => x = x - 1
                case 'L' => y = y + 1
                case 'R' => y = y - 1
            })
            (x == 0 && y == 0)
        }
    }
    

Log in to reply
 

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