Swift 4 lines 48ms


  • 0
    H

    Manipulating the number is faster but oh well

    func reverse(_ x: Int) -> Int {
    let factor = x < 0 ? -1 : 1
    let s = String(abs(x))
    let s2 = String(s.characters.reversed())
    return Int(Int32(s2) ?? 0) * factor
    }


Log in to reply
 

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