728x90
LeetCode-937
Reorder_Data_in_LogFile : reorder log files
์ฒซ๋ฒ์งธ ๋ฌธ์ ์๋ณ์ ex) "dig2 a","dig1 b"-> "a","b"
Myanswer
class Solution:
def reorderLogFiles(self, logs: List[str]) -> List[str]:
let = []
digit = []
for i in logs:
if i.split()[1].isdigit()==False:
let.append(i)
else:
digit.append(i)
let.sort(key = lambda x: (x.split()[1:], x.split()[0]))
#digit.sort(key = lambda x: x.split()[1:],reverse=True)
return let + digit
Result : 38ms Memory: 14mb
๋ฐ์ํ
'๐ข One step' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
LeetCode - Time complexity ์๊ฐ ๋ณต์ก๋ (0) | 2023.03.02 |
---|---|
[leetcode-819] Most Common Word (0) | 2023.03.02 |
[leetcode-344] ReverseString (0) | 2023.02.27 |
[leetcode-125] Palindrome + Slicing (0) | 2023.02.27 |
[leetcode-125] Palindrome (0) | 2023.02.26 |