Bluefissure's Blog

A Place for Recording

0%

LeetCode-937 Reorder Log Files

题目链接

题意

两种log:letter-log除了identifier均为小写字母,digit-log除了identifier均为数字,要求将letter-log提取到digit-log前面,并对letter-log进行字典排序

思路

Python大法好

代码

1
2
3
4
5
6
7
8
9
10
class Solution:
def reorderLogFiles(self, logs):
letter_logs = []
digit_logs = []
for log in logs:
if str.isdigit(log.split(" ")[1]):
digit_logs.append(log)
else:
letter_logs.append(log)
return sorted(letter_logs, key=lambda x: " ".join([item for item in x.split(" ")[1:]])) + digit_logs