Simple solution. Runtime > 96%
\n\nclass Solution:\n    def minimumCost(self, nums: List[int]) -> int:\n        nums.sort()\n        mediana = str(nums[len(nums) // 2])\n        half = median
![\u0421\u043D\u0438\u043C\u043E\u043A \u044D\u043A\u0440\u0430\u043D\u0430 2024-01-16 \u0432 16.57.23.png](https://assets.leetcode.com/users/images/8a02e0b3-c938-4a36-9ad0-6f73e6d0289b_1705413529.1352315.png)\n```\nclass Solution:\n    def minimumCost(self, nums: List[int]) -> int:\n        nums.sort()\n        mediana = str(nums[len(nums) // 2])\n        half = mediana[:(len(mediana) + 1) // 2]\n        min_cost, find_cost = inf, lambda x: sum(abs(n - x) for n in nums)\n        for new_half in range(int(half) - 1, int(half) + 2):\n            new_half = str(new_half) if new_half else \'\'\n            if len(mediana) % 2:\n                if len(half) < len(new_half):\n                    palindrom = new_half[:-1] + new_half[-2::-1]\n                elif len(half) > len(new_half):\n                    palindrom = new_half + new_half[::-1] if new_half else \'0\'\n                else:\n                    palindrom = new_half[:-1] + new_half[::-1]\n            else:\n                if len(half) < len(new_half):\n                    palindrom = new_half + new_half[-2::-1]\n                elif len(half) > len(new_half):\n                    palindrom = new_half + \'9\' + new_half[::-1]\n                else:\n                    palindrom = new_half + new_half[::-1]\n            min_cost = min(find_cost(int(palindrom)), min_cost)\n        return min_cost\n```
['Python3']