3 lines of Swift


  • 0
    S
    func reverse(_ x: Int32) -> Int32 {
      guard let value = Int32(String(String(abs(x)).reversed())) else {
        return 0
      }
      return (x < 0 ? -value : value)
    }
    

Log in to reply
 

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