Java | 99.9% Faster |  𝐖𝐢𝐭𝐡 𝐄𝐱𝐩𝐥𝐚𝐧𝐚𝐭𝐢𝐨𝐧
There are two list. One of them keep to digits, second one keep to letters.\n2. Add digit to digit list directly If it is digit(deciding by ascii value).\n3. Ad
1. There are two list. One of them keep to digits, second one keep to letters.\n2. Add digit to digit list directly If it is digit(deciding by ascii value).\n3. Add letter logs to list in order.\n4. Manipulate logs variable. Firstly add all letter list then add all digit list.\n5. Return logs variable.\n\n\n\n\n```java\npublic String[] reorderLogFiles(String[] logs) {\n\tList<String> digits = new ArrayList<>();\n\tList<String> letters = new ArrayList();\n\n\tfor (String log : logs) {\n\t\tString remain = log.substring(log.indexOf(" ") + 1);\n\t\tif (remain.charAt(0) > 47 && remain.charAt(0) < 58)       // if it is digit,  add to digit list\n\t\t\tdigits.add(log);\n\t\telse\n\t\t\taddLetterInOrder(letters, log);                        // if it is letter,  add to list in order\n\t}\n\n\tint i = 0;\n\tfor (String s : letters)\n\t\tlogs[i++] = s;\n\n\tfor (String digit : digits)\n\t\tlogs[i++] = digit;\n\n\treturn logs;\n}\n\nprivate void addLetterInOrder(List<String> list, String log) {\n\tif (list.isEmpty()) {\n\t\tlist.add(log);\n\t\treturn;\n\t}\n\tString logRemain = log.substring(log.indexOf(" ") + 1);                    // remain part of current log to compare items of letter list\n\tfor (int i = 0; i < list.size(); i++) {\n\t\tString current = list.get(i);\n\t\tString resRemain = current.substring(current.indexOf(" ") + 1);\n\t\tint equality = logRemain.compareTo(resRemain);\n\t\tif (equality < 0) {\n\t\t\tlist.add(i, log);\n\t\t\treturn;\n\t\t} else if (equality == 0) {                                             // if remaining parts are equals, compare original log string\n\t\t\tif (log.compareTo(current) <= 0) {\n\t\t\t\tlist.add(i, log);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\tlist.add(log);\n}\n```\n\n\n![image](https://assets.leetcode.com/users/images/1e7f62f1-185d-47d5-93ce-d2265b4789c3_1656097314.0059175.png)\n
['Java']