https://leetcode.com/problems/excel-sheet-column-title/description/
Excel Sheet Column Title - LeetCode
Excel Sheet Column Title - Given an integer columnNumber, return its corresponding column title as it appears in an Excel sheet. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... Example 1: Input: columnNumber = 1 Output: "A" Example 2
leetcode.com
짱짱 쉬워보이는데 은근히 까다롭다.
규칙을 잘 찾아야되는데 일반적인 26진수라고 생각하고 접근하면 잘 안된다.
1-indexed이기 때문에 이걸 꼭 고려하고 -1씩 해주는걸 생각해야된다.
class Solution:
def convertToTitle(self, x: int) -> str:
return "" if not x else self.convertToTitle((x - 1) // 26) + chr(ord('A') + (x - 1) % 26)'코딩 테스트 및 알고리즘 > leetcode for google' 카테고리의 다른 글
| leetcode medium : Magic Squares In Grid (0) | 2023.01.15 |
|---|---|
| leetcode medium : Triangle (0) | 2023.01.13 |
| leetcode easy : Intersection of Two Linked List (0) | 2023.01.10 |
| leetcode medium : next permutation 복습 (0) | 2023.01.06 |
| leetcode hard : Shortest Path Visiting All Nodes (0) | 2023.01.02 |