처음에 주석으로 풀었는데, n번째 인덱스 이전의 문자들이 정렬에 고려되지 않는 문제가 생겼다
[반례] ["aea", "ba", "ce", "aee"], 1 -> ["ba", "aea", "aee", "ce"]
그렇기 때문에 문자 전체를 뒤에 잇는 것으로 해결하였다.
def solution(strings, n):
# answer = sorted(strings, key=lambda x: x[n:])
answer = sorted(strings, key=lambda x: x[n]+x)
return answer
'언어' 카테고리의 다른 글
명예의 전당 (0) | 2023.12.15 |
---|---|
leetcode (1) (1) | 2023.12.15 |
완전탐색 (0) | 2023.12.13 |
join on 다중 조건 & cast type 실험 (0) | 2023.12.13 |
list.count(n) (0) | 2023.12.12 |