日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

LeetCode--171--Excel表列序号

發(fā)布時間:2023/12/18 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 LeetCode--171--Excel表列序号 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

問題描述:

給定一個Excel表格中的列名稱,返回其相應的列序號。

例如,

A -> 1B -> 2C -> 3...Z -> 26AA -> 27AB -> 28 ...

示例 1:

輸入: "A" 輸出: 1

示例?2:

輸入: "AB" 輸出: 28

示例?3:

輸入: "ZY" 輸出: 701

方法1:(轉)

1 class Solution(object): 2 def titleToNumber(self, s): 3 """ 4 :type s: str 5 :rtype: int 6 """ 7 sum_ = 0 8 for i in range(len(s)): 9 tmp = ord(s[i]) - 65 + 1 10 sum_ = tmp + 26 * sum_ 11 return sum_

ABC = step1:sum_ = 1 + 26 × 0 ;step2:sum_ = 2 + 26 × 1;step3: sum_ = 3 + 26 × 28?

方法2:(轉)

1 class Solution(object): 2 def get_int(self,strs): 3 return ord(strs) - 64 4 5 def titleToNumber(self, s): 6 """ 7 :type s: str 8 :rtype: int 9 """ 10 result = 0 11 s = s[::-1] 12 for i in range(len(s)): 13 if i==0: 14 result +=self.get_int(s[i]) 15 else: 16 result += 26**i*self.get_int(s[i]) 17 return result

ABC ->CBA = 3 + 26^1×2 + 26^2×1

2018-09-15?10:03:08

轉載于:https://www.cnblogs.com/NPC-assange/p/9650069.html

總結

以上是生活随笔為你收集整理的LeetCode--171--Excel表列序号的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。