Created
July 29, 2025 11:11
-
-
Save inspirit941/6a13fb6d8d6438eb2ebe55b9f8a1c37f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| def solution(n, bans): | |
| # 26 기준으로 | |
| # 1 ~ 26 = 1글자 'a'~ => n // 26 = 0인 것 | |
| # 26+1 ~ 26*2 = 2글자 'aa' ~ n // 26 = 1인 것 | |
| # 26*2+1 ~ 26*3 = 2글자 'ba' ~ | |
| # 26*25 ~ 26*26 = 2글자 끝 | |
| # 26*26+1 ~ ... 3글자 'aaa'... | |
| # 26진수? | |
| # 삭제되었다 -> 삭제된 갯수만큼 실제 원하는 숫자를 늘려줘야 한다. | |
| table = {} | |
| for idx, value in enumerate(list('abcdefghijklmnopqrstuvwxyz'), 1): | |
| table[value] = idx | |
| bans = sorted(bans, key=lambda x: (len(x), x)) | |
| actual_number = n | |
| # 앞에서 삭제된 거 찾기 | |
| for string in bans: | |
| string_list = list(reversed(string)) | |
| number = 0 | |
| for idx in range(len(string)): | |
| number += (math.pow(26, idx) * table[string_list[idx]]) | |
| if number > actual_number: | |
| break | |
| actual_number += 1 | |
| # n을 26진수로 표현 | |
| n_26 = [] | |
| while actual_number > 0: | |
| share = actual_number // 26 | |
| remainer = actual_number % 26 | |
| if remainer == 0: | |
| remainer = 26 | |
| share -= 1 | |
| n_26.append(remainer) | |
| actual_number = share | |
| n_26.reverse() | |
| alphabets = list('abcdefghijklmnopqrstuvwxyz') | |
| answer = [] | |
| for value in n_26: | |
| answer.append(alphabets[value-1]) | |
| return "".join(answer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment