leetcode 937

861 ワード

質問する
https://leetcode.com/problems/reorder-data-in-log-files/
説明する
class Solution:
    def reorderLogFiles(self, logs: List[str]) -> List[str]:
        sorted_logs = []
        for idx, log in enumerate(logs):
            log_content = list(log.split())
            identifier, content = log_content[0], ' '.join(log_content[1:])
            if content[0].isdigit(): # 숫자이면
                sorted_logs.append((1,0,0,idx,log))
                
            else : # 문자이면
                sorted_logs.append((0,content,identifier,idx,log))
                
        sorted_logs.sort(key=lambda x: (x[0],x[1],x[2],x[3]))
        print(sorted_logs)
        return ([log[4] for log in sorted_logs])