Easy
Reorder Log Files — Python
Full explanation · Time O(nlogn * l) · Space O(l)
# Time: O(nlogn * l), n is the length of files, l is the average length of strings
# Space: O(l)
class Solution(object):
def reorderLogFiles(self, logs):
"""
:type logs: List[str]
:rtype: List[str]
"""
def f(log):
i, content = log.split(" ", 1)
return (0, content, i) if content[0].isalpha() else (1,)
logs.sort(key=f)
return logs