leetcode刷題--Excel Sheet Column Title
題目:把給定的正整數轉換成excel裡的列標
舉個例子:
1 -> A
2 -> B
3 -> C
...
26 -> Z
27 -> AA
28 -> AB
那麼怎麼做呢,其實可以看成是一個26進位制的數。。。數字就是A到Z,那隻要做除法和取餘就可以實現了。不斷的取餘得出對應位的字元拼接即可。
程式碼:
class Solution:
# @param {integer} n
# @return {string}
def convertToTitle(self, n):
result = ""
N=n-1
while(1):
if N<26:
char=chr(65+N%26)
result = char + result
break
char=chr(65+N%26)
result = char + result
N=int(N/26-1)
return result
相關文章
- leetcode刷題--Excel Sheet Column NumberLeetCodeExcel
- Leetcode 168. Excel Sheet Column TitleLeetCodeExcel
- Leetcode168. Excel Sheet Column TitleLeetCodeExcel
- Excel Sheet Column Title Excel表列名稱Excel
- [LeetCode] Excel Sheet Column NumberLeetCodeExcel
- Leetcode 171. Excel Sheet Column NumberLeetCodeExcel
- 171. Excel Sheet Column Number--LeetCode RecordExcelLeetCode
- Excel Sheet Column Number Excel表列序號Excel
- excel合併sheetExcel
- LeetCode刷題整理LeetCode
- leetcode刷題(一)LeetCode
- LeetCode刷題 堆LeetCode
- LeetCode 刷題—樹LeetCode
- LeetCode 刷題指南(一):為什麼要刷題LeetCode
- LeetCode 刷題筆記LeetCode筆記
- leetcode刷題筆記LeetCode筆記
- LeetCode刷題記錄LeetCode
- 如何使用leetcode刷題LeetCode
- leetcode刷題--Majority ElementLeetCode
- leetcode刷題--Count PrimesLeetCode
- leetcode刷題--Reverse BitsLeetCode
- leetcode刷題--Rotate ArrayLeetCode
- leetcode刷題--Count and SayLeetCode
- Leetcode刷題分類LeetCode
- Leetcode刷題準備LeetCode
- LeetCode刷題—陣列LeetCode陣列
- 用Pandas讀寫Excel檔案-輸出單sheet和多sheetExcel
- Leetcode刷題——求眾數LeetCode
- leetcode刷題筆記605LeetCode筆記
- Leetcode刷題系列彙總LeetCode
- leetcode刷題--Happy NumberLeetCodeAPP
- leetcode刷題--Number of 1 BitsLeetCode
- leetcode刷題記錄 661~LeetCode
- LeetCode刷題之第701題LeetCode
- Leetcode已刷題目題解彙總LeetCode
- leetcode排序專題演算法刷題LeetCode排序演算法
- 用Rust刷leetcode第十題RustLeetCode
- 用Rust刷leetcode第八題RustLeetCode