C++ || Beginner 🔥✅🔥
\n\n\n# Code\n\nclass Solution {\npublic:\n    bool palindrome(int n)\n    {\n        string s=to_string(n);\n        int l=0,r=s.length()-1;\n        while(l<=
\n\n\n# Code\n```\nclass Solution {\npublic:\n    bool palindrome(int n)\n    {\n        string s=to_string(n);\n        int l=0,r=s.length()-1;\n        while(l<=r)\n        {\n            if(s[l]!=s[r])\n                return false;\n            l++;\n            r--;\n        }\n        return true;\n    }\n    int maxPalindrome(int n)\n    {\n        while(true)\n        {\n            if(palindrome(n))\n                return n;\n            n++;\n        }\n        return 0;\n    }\n    int minPalindrome(int n)\n    {\n        while(n>0)\n        {\n            if(palindrome(n))\n                return n;\n            n--;\n        }\n        return 0;\n    }\n    long long minimumCost(vector<int>& nums) {\n        sort(nums.begin(),nums.end());\n        long long median;\n        if(nums.size()%2==0)\n            median=(nums[(nums.size()-1)/2]+nums[nums.size()/2])/2;\n        else\n            median=(nums[(nums.size()-1)/2]);\n        int mini=minPalindrome(median);\n        int maxi=maxPalindrome(median);\n        long long minres=0,maxres=0;\n        for(auto num:nums)\n        {\n            minres+=abs(num-mini);\n            maxres+=abs(num-maxi);\n        }\n        return min(minres,maxres);\n    }\n};\n```
['Math', 'Greedy', 'Sorting', 'C++']