Simple java solution
Complexity\n- Time complexity: O(n log n)\n\n- Space complexity: O(1)\n\n# Code\n\nclass Solution {\n    public long minimumCost(int[] nums) {\n        Arrays.s
# Complexity\n- Time complexity: $$O(n log n)$$\n\n- Space complexity: $$O(1)$$\n\n# Code\n```\nclass Solution {\n    public long minimumCost(int[] nums) {\n        Arrays.sort(nums);\n        int med=0,len=nums.length;\n        med=nums[len/2];\n        int num1=palindrome1(med),num2=palindrome2(med);\n        long sum1=findsum(nums,num1),sum2=findsum(nums,num2);\n        return sum1 > sum2 ? sum2 : sum1;\n    }\n    private int palindrome1(int num)\n    {\n        while(!check(num))\n        {\n            num--;\n        }\n        return  num;\n    }\n    private int palindrome2(int num)\n    {\n        while(!check(num))\n        {\n            num++;\n        }\n        return num;\n    }\n    private boolean check(int n)\n    {\n        long dup=n,rev=0;\n        while(dup!=0)\n        {\n            rev=rev*10+(dup%10);\n            dup/=10;\n        }\n        return rev==n;\n    }\n    private long findsum(int nums[], int n)\n    {\n        long sum=0;\n        for(int i=0;i<nums.length;i++)\n        {\n            sum=sum+Math.abs(n-nums[i]);\n        }\n        return sum;\n    }\n}\n```
['Java']