JAVA | Replace to '9' and '0' | Faster than 100%🚩
Simple JAVA Approach\nDo UPVOTE!!\u2705\n\npublic int minMaxDifference(int num) {\n        StringBuilder n = new StringBuilder(Integer.toString(num));\n        
**Simple JAVA Approach**\nDo UPVOTE!!\u2705\n```\npublic int minMaxDifference(int num) {\n        StringBuilder n = new StringBuilder(Integer.toString(num));\n        int len = n.length();\n        StringBuilder max = new StringBuilder();\n        boolean flag = false;\n        char f = \' \';\n        \n        for(int i=0;i<len;i++){\n            char ch = n.charAt(i);\n            \n            if(ch == f) max.append(\'9\');\n            \n            else if(ch != \'9\' && !flag){\n                f=ch;\n                flag=true;\n                max.append(\'9\');\n            }\n            else max.append(ch);\n        }\n        \n        StringBuilder min = new StringBuilder();\n        min.append(\'0\');\n        f = n.charAt(0);\n        \n        for(int i=1;i<len;i++){\n            char ch = n.charAt(i);\n            if(ch == f) min.append(\'0\');\n            else min.append(ch);\n        }\n        return Integer.valueOf(max.toString()) - Integer.valueOf(min.toString());\n    }\n```
['Java']