[LeetCode] 937. Reorder Data in Log Files

2021. 1. 4. 22:30Problem Solving/LeetCode

https://leetcode.com/problems/reverse-string/submissions/

 

Reverse String - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

내 풀이

class Solution:
def reorderLogFiles(self, logs: List[str]) -> List[str]:
char_log: str = []
int_log: str = []
# 문자, 숫자로그 판별
for s in logs:
if s.split()[1].isdigit():
int_log.append(s)
else:
char_log.append(s)
char_log.sort(key=lambda x: (x.split()[1:], x.split()[0]))
return char_log + int_log

빠르다

 

람다 표현식을 사용했다.

이 풀이에 쓰인 파이썬 메소드

책 정보

파이썬 알고리즘 인터뷰
국내도서
저자 : 박상길
출판 : 책만 2020.07.15
상세보기
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글