Brute force and string comparison
Intuition\nSearch for the closer number to the Palindromic that cause the smaller cost.\n\n# Approach\n- Find the mediam, sort the list and choose the number in
# Intuition\nSearch for the closer number to the Palindromic that cause the smaller cost.\n\n# Approach\n- Find the mediam, sort the list and choose the number in the middle.\n- If the mediam isn\'t a Palindromic check for the closer from the left and the right and choose the one that cost the less.\n    - In order to check if a number is a Palindromic we go for the visuall solution, convert it to a string and compate with its reverse.\n    - In order to find the closer from the left and right we just go and check one number at the time to the left and right\n\n# Complexity\n- Time complexity:\n    - Sort the nums is $O(n * log(n))$\n    - Find the closer Palindromic, worse case $n$\n    - Conclusion: $O(n * log(n))$\n\n- Space complexity:\n$O(1)$\n\n# Code\n```\nclass Solution {\n    func minimumCost(_ nums: [Int]) -> Int {\n        let nums = nums.sorted().map { $0 }\n        let average =  nums[nums.count / 2] //nums.reduce(0) { $0 + $1} / nums.count\n\n        if isPalinDrome(average) {\n            // if mid is palindrome in sorted add them \n            return cost(nums, average)\n        } else {\n            // find first lower palindrome and next bigger palindrome \n            return min(\n                cost(nums, leftPalinDrome(average)), \n                cost(nums, rightPalinDrome(average+1)) )\n        }\n    }\n\n    private func leftPalinDrome(_ num: Int) -> Int {\n        //print("leftPalinDrome \\(num)")\n        if isPalinDrome(num) { return num }\n        return leftPalinDrome(num - 1)\n    }\n\n    private func rightPalinDrome(_ num: Int) -> Int {\n        //print("rightPalinDrome \\(num)")\n        if isPalinDrome(num) { return num }\n        return rightPalinDrome(num + 1)\n    }\n    \n    private func isPalinDrome(_ num: Int) -> Bool {        \n        "\\(num)" == String("\\(num)".reversed())\n    }\n\n    private func cost(_ nums: [Int], _ palindrome: Int) -> Int {\n        nums.reduce(0) { $0 + abs($1 - palindrome) }\n    }\n}\n```
['Swift']