Maximum Difference by Remapping a Digit Solution in C++
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)$$ -->\nO(n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n# Code\n```\nclass Solution {\npublic:\n    int minMaxDifference(int num) {\n        int i, j=-1,num1=0, num2=0, ans, flag=0;\n        vector<int> arr1, arr2;\n\n\n        while(num>0)\n        {\n            i = num%10;\n            num = num/10;\n            arr1.push_back(i);\n        }\n        reverse(arr1.begin(), arr1.end());\n\n\n\n        arr2 = arr1;\n        for(i=0 ; i<arr1.size() ; i++)\n        {\n            if(arr1[i]==j && flag==1)\n            {\n                arr1[i] = 0;\n            }\n            else if(arr1[i]>0 && flag==0)\n            {\n                j = arr1[i];\n                arr1[i] = 0;\n                flag=1;\n            }\n        }\n        for(i=arr1.size()-1 ; i>=0 ; i--)\n        {\n            num1 += arr1[i]*pow(10, arr2.size()-1-i);\n        }\n\n\n        j=-1;\n        flag=0;\n        for(i=0 ; i<arr2.size() ; i++)\n        {\n            if(arr2[i]==j  && flag==1)\n            {\n                arr2[i] = 9;\n            }\n            else if(arr2[i]<9  && flag==0)\n            {\n                j = arr2[i];\n                arr2[i] = 9;\n                flag=1;\n            }\n        }\n        for(i=arr2.size()-1 ; i>=0 ; i--)\n        {\n            num2 += arr2[i]*pow(10, arr2.size()-1-i);\n        }\n\n        \n        ans = num2-num1;\n        return ans;\n    }\n};\n```\n![upvote new.jpg](https://assets.leetcode.com/users/images/792a2ee3-fa92-4936-9a87-216cd9a9ac02_1682613207.1269994.jpeg)
['C++']