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
相關文章
- Excel Sheet Column Number Excel表列序號Excel
- Leetcode 168. Excel Sheet Column TitleLeetCodeExcel
- Excel Sheet Column Title Excel表列名稱Excel
- LeetCode 刷題—樹LeetCode
- LeetCode刷題 堆LeetCode
- LeetCode刷題整理LeetCode
- leetcode刷題(一)LeetCode
- LeetCode刷題記錄LeetCode
- leetcode刷題筆記LeetCode筆記
- 如何使用leetcode刷題LeetCode
- Leetcode刷題分類LeetCode
- LeetCode 刷題筆記LeetCode筆記
- Leetcode刷題準備LeetCode
- LeetCode刷題—陣列LeetCode陣列
- LeetCode刷題之第701題LeetCode
- LeetCode 刷題指南(一):為什麼要刷題LeetCode
- LeetCode - 解題筆記 - 8 - Palindrome NumberLeetCode筆記
- Leetcode刷題——求眾數LeetCode
- leetcode刷題記錄 661~LeetCode
- leetcode刷題筆記605LeetCode筆記
- Leetcode刷題系列彙總LeetCode
- Leetcode Number of islandsLeetCode
- 用Pandas讀寫Excel檔案-輸出單sheet和多sheetExcel
- leetcode刷題筆記(3)(python)LeetCode筆記Python
- LeetCode刷題(javascript,python3)LeetCodeJavaScriptPython
- 用 Rust 刷 leetcode 第七題RustLeetCode
- 用 Rust 刷 leetcode 第一題RustLeetCode
- 用 Rust 刷 leetcode 第三題RustLeetCode
- 用 Rust 刷 leetcode 第二題RustLeetCode
- 用Rust刷leetcode第九題RustLeetCode
- 用Rust刷leetcode第八題RustLeetCode
- 用 Rust 刷 leetcode 第六題RustLeetCode
- 用 Rust 刷 leetcode 第五題RustLeetCode
- 用 Rust 刷 leetcode 第四題RustLeetCode
- 用Rust刷leetcode第十題RustLeetCode
- leetcode排序專題演算法刷題LeetCode排序演算法
- [LeetCode] Third Maximum NumberLeetCode
- [LeetCode] Find the Duplicate NumberLeetCode
- Leetcode 9 Palindrome NumberLeetCode