Clean Swift Solution, O(nlogn)
The solution does not use a separate array to sort out the digits and non digits. Everything is done in the sorted closure. Clean and functional.\n\nTime comple
The solution does not use a separate array to sort out the digits and non digits. Everything is done in the sorted closure. Clean and functional.\n\nTime complexity: `O(nlogn)`\n\n```\nclass Solution {\n    func reorderLogFiles(_ logs: [String]) -> [String] {\n        let sorted = logs.sorted { log1, log2 -> Bool in\n            let split1 = log1.split(separator: " ", maxSplits: 1)\n            let split2 = log2.split(separator: " ", maxSplits: 1)\n\n            let afterID1 = split1[1]\n            let afterID2 = split2[1]\n\n            let isDigit1 = afterID1.first!.isNumber\n            let isDigit2 = afterID2.first!.isNumber\n\n            if !isDigit1 && !isDigit2 {\n                if afterID1.compare(afterID2) == .orderedSame {\n                    return split1[0].compare(split2[0]) == .orderedAscending\n                } else {\n                    return afterID1.compare(afterID2) == .orderedAscending\n                }\n            } else if isDigit1 && isDigit2 {\n                return afterID1.compare(afterID2) == .orderedSame\n            } else {\n                return afterID1.compare(afterID2) == .orderedDescending\n            }\n        }\n        return sorted\n    }\n}\n```
[]