Using inbuilt string functions - More practice on inbuilt string functions
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nOnly bad thing is we ar
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nOnly bad thing is we are traversing two times. which we can reduce to one by using "flag" boolean valriable rather than "break".\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$\n\n# Code\n```\nclass Solution {\n    public int minMaxDifference(int num) {\n\n        //converting to string\n        String n = Integer.toString(num);\n        int len = n.length();\n        //define minimum and maximum as number it self for test case like 999999....\n        int mini = num;\n        int maxi = num;\n\n        for(int i=0; i<len; i++){\n            char c = n.charAt(i);\n            //for maximum number\n            //if the initials digits are 9 itself we dont change\n            //else change\n            if(c!=\'9\'){\n                // repalcing all selected digit with 9 \n                maxi = Integer.parseInt(n.replaceAll(Character.toString(c),"9"));\n                break;\n            } else{\n                continue;\n            }\n        }\n\n            //similar to maximum \n            // just replace with 0\n        for(int i=0; i<len; i++){\n            char c = n.charAt(i);\n            if(c!=\'0\'){\n                mini = Integer.parseInt(n.replaceAll(Character.toString(c),"0"));\n                break;\n            } else{\n                continue;\n            }\n        }\n        \n        //return the diiference\n        return maxi-mini;\n        \n    }\n}\n```
['Java']