Simple JAVA || O(N) Approach
\n# Code\n\nclass Solution {\n    public int minMaxDifference(int num) {\n        \n        \n        String a=num+"";\n        String maxstr="";int k=0;\n     
\n# Code\n```\nclass Solution {\n    public int minMaxDifference(int num) {\n        \n        \n        String a=num+"";\n        String maxstr="";int k=0;\n        for(int i=0;i<a.length();i++)\n        {\n            String replacemax=a.replaceAll(a.charAt(i)+"","9");\n        if(a.equals(replacemax)){\n            \n            continue;\n                                }\n         else{\n             k=1;\n             maxstr=replacemax;\n             break;\n         }\n        }\n        if(k==0)maxstr=a;\n        String replacemin=a.replaceAll(a.charAt(0)+"","0");\n        \n        \n        \n        \n        long max=Long.parseLong(maxstr);\n        long min=Long.parseLong(replacemin);\n        \n        return (int)(max-min);\n        \n        \n    }\n}\n```
['Java']