Leetcode 974 Solution
This article provides solution to leetcode question 974 (reorder-data-in-log-files)
Access this page by simply typing in "lcs 974" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/reorder-data-in-log-files
Solution
class Solution:
def reorderLogFiles(self, logs: List[str]) -> List[str]:
digit_logs = []
letter_logs = []
for log in logs:
tokens = log.split(' ')
if tokens[1].isdigit():
digit_logs.append(log)
else:
letter_logs.append((" ".join(tokens[1:]) + " " + tokens[0], log))
letter_logs.sort()
return [log for _, log in letter_logs] + digit_logs