Python3 👍||⚡clean solution only 12 lines🔥|| simple explain ||
Intuition\n Describe your first thoughts on how to solve this problem. \nIf one wishes to find a number x such that the sum of distances between x and all numbe
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf one wishes to find a number x such that the sum of distances between x and all numbers in the array is minimal, that number would be the median. In the case of an even-length array, any number between the two middle numbers can serve as the solution.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nStep1 : Find median.\nStep2 : Move both left and right from the median to identify palindromic numbers.\nStep3 : Return the minimal among them.\n\n# Complexity\n- Time complexity: O(log(nums[i]) * sqrt(nums[i]) + n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def minimumCost(self, nums: List[int]) -> int: \n        def check(start,end,interval):\n            for i in range(start,end,interval):\n                if str(i) == str(i)[::-1]:\n                    cost = 0\n                    for n in nums:\n                        cost += abs(i-n)\n                    return cost \n            return inf\n        n = len(nums)\n        me = int(median(nums))\n        return min(check(me,-1,-1),check(me+1,10**9,1))\n```
['Python', 'Python3']