I don't know what is scala..


  • 0
    A

    import scala.util.Try

    object Solution {
    def reverse(x: Int): Int = {
    val ans = if (x >= 0) {
    x.toString.reverse
    } else {
    x.toString.reverse.substring(0, x.toString.length - 1)
    }
    val t = if (x < 0) Try(-ans.toInt)
    else Try(ans.toInt)
    t.getOrElse(0)
    }
    }


Log in to reply
 

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