Reorder Data in Log Files
- 1 min read
- String
- LC-Medium
Solution
- Just use a custom sort comparator function- look at the code you'll understand
| Time | Space | Explanation |
|---|
O() | O() | |
def reorderLogFiles(self, logs: List[str]) -> List[str]:
def get_key(log):
_id, rest = log.split(' ', maxsplit=1)
return (0, rest, _id) if rest[0].isalpha() else (1, )
return sorted(logs, key=get_key)