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 |
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 49. Group Anagrams (0) | 2023.02.07 |
---|---|
leetcode 819. Most Common Word (0) | 2023.02.07 |
leetcode 1967. Number of Strings That Appear as Substrings in Word (2) | 2023.02.03 |
백준 27332 11 月 (November) (0) | 2023.02.01 |
백준 27294 몇개고? (0) | 2023.01.31 |
댓글