Swift Solution


  • 0
    L
    precedencegroup PowerPrecedence { higherThan: MultiplicationPrecedence }
    infix operator ^^ : PowerPrecedence
    func ^^ (radix: Int, power: Int) -> Int {
        
        return Int(pow(Double(radix), Double(power)))
    }
    
    class Solution {
        
        func reverse(_ x: Int) -> Int {
            
            var newX = 0
        
            var digit = 0
            
            while  (x/10^^digit)%10 != 0 || (x/10^^digit) != 0 {
                
                let n = (x/10^^digit)%10
                
                newX = newX*10 + n
                
                if newX > 2^^31 - 1 || newX < -2^^31 {
                    
                    return 0
                }
                digit = digit + 1
            }
            return newX
        }
    }
    

Log in to reply
 

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