Easy Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public long minimumCost(int[] nums) {\n        int n = nums.length;\n        Arrays.sort(nums);\n        int middle = nums[n/2];\n        int inc = middle;\n        int dec = middle;\n\n        while(!isPal(inc)) inc++; \n        while(!isPal(dec)) dec--;\n\n        return Math.min(calculateCost(nums,inc), calculateCost(nums,dec));\n    }\n\n\n    public boolean isPal(int n) {\n        int r, sum = 0, temp;\n        temp = n;\n        while (n > 0) {\n            r = n % 10; \n            sum = (sum * 10) + r;\n            n = n / 10;\n        }\n        return temp == sum;\n    }\n\n    public long calculateCost(int[] nums, int r) {\n        long cost = 0;\n        for (int n: nums) cost += Math.abs(n - r);\n        return cost;\n    }\n}\n```
['Math', 'Java']