Java |  Easy Solution | Beats 98%
\nclass Solution {\n    public long minimumCost(int[] nums) {\n        Arrays.sort(nums);\n        int len = nums.length;\n        \n        int m = len % 2 != 
```\nclass Solution {\n    public long minimumCost(int[] nums) {\n        Arrays.sort(nums);\n        int len = nums.length;\n        \n        int m = len % 2 != 0 ? len / 2 : len/2 - 1;\n        int previousPalindrome = getPreviousPalindrome(nums[m]);\n        int nextPalindrome = getNextPalindrome(nums[m]);\n        long ans1 = 0;\n        long ans2 = 0;\n        for (int i = 0; i < len; i++){\n            ans1 += Math.abs(previousPalindrome - nums[i]);\n            ans2 += Math.abs(nextPalindrome - nums[i]);\n        }\n        return Math.min(ans1, ans2);\n    }\n    \n    int getPreviousPalindrome(int num){\n        int previousPalindrome = num;\n        int nextPalindrome = num;\n        \n        while(!isPalindrome(previousPalindrome)){\n            previousPalindrome--;\n        }\n        return previousPalindrome;\n    }\n\n    int getNextPalindrome(int num){\n        int nextPalindrome = num;\n        \n        while(!isPalindrome(nextPalindrome)){\n            nextPalindrome++;\n        }\n        return nextPalindrome;\n    }\n    \n    public boolean isPalindrome(int num){\n        int copyNum = num;\n        int reverseNum = 0;\n        \n        while(num > 0) {\n            reverseNum = reverseNum * 10 + num % 10;\n            num /= 10;\n        }\n        return copyNum == reverseNum;\n    }\n}\n```
[]