leetcode刷題--Excel Sheet Column Number
題目:給出一個excel的列編號,求出對應的數字
這道題和上一題差不多,就是倆過程翻過來
思路可以是這樣,dict存放對映,然後對應成數字再計算
程式碼:
class Solution:
# @param {string} s
# @return {integer}
def titleToNumber(self, s):
fix=ord("A")
n=len(s)
result=0
map={"A":1,"B":2,"C":3,"D":4,"E":5,"F":6,"G":7,"H":8,"I":9,"J":10,"K":11,"L":12,"M":13,"N":14,"O":15,"P":16,"Q":17,"R":18,"S":19,"T":20,"U":21,"V":22,"W":23,"X":24,"Y":25,"Z":26,}
for i in range(n):
result+=(26**(n-i-1))*map[s[i]]
return result
相關文章
- [LeetCode] Excel Sheet Column NumberLeetCodeExcel
- leetcode刷題--Excel Sheet Column TitleLeetCodeExcel
- Leetcode 171. Excel Sheet Column NumberLeetCodeExcel
- 171. Excel Sheet Column Number--LeetCode RecordExcelLeetCode
- Excel Sheet Column Number Excel表列序號Excel
- Leetcode 168. Excel Sheet Column TitleLeetCodeExcel
- Leetcode168. Excel Sheet Column TitleLeetCodeExcel
- Excel Sheet Column Title Excel表列名稱Excel
- leetcode刷題--Happy NumberLeetCodeAPP
- leetcode刷題--Number of 1 BitsLeetCode
- 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 第 9 題(Palindrome Number)LeetCode
- LeetCode 第 65 題(Valid Number)LeetCode
- LeetCode 題解(252) : Find the Duplicate NumberLeetCode
- Leetcode刷題——求眾數LeetCode
- leetcode刷題筆記605LeetCode筆記
- Leetcode刷題系列彙總LeetCode
- leetcode刷題記錄 661~LeetCode
- LeetCode刷題之第701題LeetCode
- LeetCode 第 191 題 (Number of 1 Bits)LeetCode