본문 바로가기
python-algorithm

leetcode 937. Reorder Data in Log Files

by 무적김두칠 2023. 2. 7.

https://leetcode.com/problems/reorder-data-in-log-files/description/

 

Reorder Data in Log Files - LeetCode

Reorder Data in Log Files - You are given an array of logs. Each log is a space-delimited string of words, where the first word is the identifier. There are two types of logs: * Letter-logs: All words (except the identifier) consist of lowercase English le

leetcode.com

 

1
2
3
4
5
6
7
8
9
10
11
class Solution:
    def reorderLogFiles(self, logs: List[str]) -> List[str]:
        letters, digits = [], []
        for log in logs:
            if log.split()[1].isalpha():
                letters.append(log)
            else:
                digits.append(log)
        letters.sort(key= lambda x: (x.split()[1:], x.split()[0]))
 
        return letters + digits
cs
반응형

댓글