Reverse Integer in SCALA


  • 0
    S

    Here is the better solution if to be written in scala :

    object Solution {
        def reverse(x: Int): Int = {
           def reverset(x : Int, acc : Int =0):Int = {
            if(x == 0)
              acc
            else{
              if(Math.abs(Int.MaxValue / 10)  < Math.abs(acc)) 0 else 
                          reverset(x/10,acc*10+(x%10))
            }
          }
        reverset(x)
        }
    }
    

Log in to reply
 

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