-
[leetcode - python] Excel SheetProblem Solving 2022. 7. 20. 00:15
문제 설명
https://leetcode.com/problems/excel-sheet-column-number/submissions/
Excel Sheet Column Number - 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
- 난이도 - Easy
A~Z가 1~26열을 나타내고, 27 이상은 AA와 같이 알파벳의 조합으로 표현될 때, 주어진 알파벳 조합이 몇열인지 구하는 문제
관련 개념
문자열, 아스키코드
접근 방법
26^(자릿수) + 알파벳에 해당하는 열
을 아스키 코드를 이용해 문자로 숫자로 변환해 계산
답안 코드
Runtime: 52 ms (47.28%)
Memory Usage: 14 MB (10.48%)class Solution: def titleToNumber(self, columnTitle: str) -> int: result = 0 location = len(columnTitle) - 1 for c in columnTitle: result += 26 ** location * (ord(c) - ord('A') + 1) location -= 1 return result
'Problem Solving' 카테고리의 다른 글
[백준] 14225. 부분수열의 합 - Python3 (0) 2023.01.10 [백준] 19071. 외판원 순회2 - C++ (0) 2023.01.10 [leetcode - Python] Roman to Integer (0) 2022.07.19 [leetcode - python] Majority Element (0) 2022.07.18 [leetcode - C] Maximum Subarray (0) 2022.07.16