Intuitive Java Solution
Idea\nFor digit-logs, we need to keep the original order, so we just add these to the output list (use LinkedList) in the first pass and letter-logs to maxHeap.
**Idea**\nFor digit-logs, we need to keep the original order, so we just add these to the output list (use LinkedList) in the first pass and letter-logs to maxHeap.\nFinally, we do `addFirst` to our list retrieving letter-logs according to the reverse lex order.\n\n```\npublic String[] reorderLogFiles(String[] logs) {\n        LinkedList<String> list = new LinkedList<>();\n        PriorityQueue<String> pq = new PriorityQueue<>(new Comparator<String>(){\n            public int compare(String s1, String s2){\n                int i1 = s1.indexOf(" "), i2 = s2.indexOf(" ");\n                String id1 = s1.substring(0, i1), id2 = s2.substring(0, i2);\n                String log1 = s1.substring(i1+1), log2 = s2.substring(i2+1);\n                if(log1.equals(log2))\n                    return id2.compareTo(id1);\n                return log2.compareTo(log1);\n            }\n        });\n        for(String s : logs){\n            String[] w = s.split(" ");\n            if(\'0\' <= w[1].charAt(0) && w[1].charAt(0) <= \'9\')\n                list.add(s);\n            else\n                pq.add(s);\n        }\n        while(!pq.isEmpty())\n            list.addFirst(pq.remove());\n        String[] res = new String[logs.length];\n        int i = 0;\n        for(String s : list)\n            res[i++] = s;\n        return res;\n    }\n```
[]