Swift Solution


  • 0
    R
    private extension String {
        
        func reverse() -> String {
            
            var strArray = Array(self)
            let halfCount = abs(self.count/2)
            let count = self.count
        
            for i in 0..<halfCount {
                
                let swapChar = strArray[i]
                strArray[i] = strArray[count - i - 1]
                strArray[count - i - 1] = swapChar
            }
            
            return String(strArray)
        }
    }
    

Log in to reply
 

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