Scala solution

  • 0

    key is back to original position
    so number of U, D, L, and R should be same

    def judgeCircle(moves: String): Boolean = {
           val u = moves.filter(_ == 'U').size
           val d = moves.filter(_ == 'D').size
           val l = moves.filter(_ == 'L').size
           val r = moves.filter(_ == 'R').size
           u == d && l == r

Log in to reply

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