leetcode-mid-math -171. Excel Sheet Column Number
2024-09-01 01:08:04
mycode 90.39%
class Solution(object):
def titleToNumber(self, s):
"""
:type s: str
:rtype: int
"""
res = 0
for alpha in s:
res = (ord(alpha) - 64) + res*26
return res
参考:
carry实际上就是十进制中的指数
class Solution(object):
def titleToNumber(self, s):
"""
:type s: str
:rtype: int
"""
def _map(ch):
chn = ord(ch)
assert chn >= ord('A') and chn <= ord('Z')
return chn - ord('A') + 1
lens = len(s)-1
carry = 1
val = 0
while lens >=0:
num = _map(s[lens])*carry
val = val + num
carry *= 26
lens -= 1
return val
最新文章
- SqlServer windowss身份登陆和sa身份登陆
- NPOI操作excel
- (转)python爬取拉勾网信息
- iOS启动图和开屏广告图,类似网易
- 【poj3537】 Crosses ans Crosses
- 多线程——GCD
- Programming Impala Applications
- Struts2学习笔记1
- diff函数的实现——LCS的变种问题
- 配置并学习微信JS-SDK(3)&mdash;菜单接口
- CentOS 7安装Teamviewer 12
- Java集合框架学习(一)List
- centOS 6启动流程
- Problem : 1013 ( Digital Roots )
- 4.namespace
- 【原创】大数据基础之Hive(5)hive on spark
- 移动Web端资源整合
- VS2012 VS2015打开项目加载失败
- GameObject.Find与Transform.Find的区别
- JMeter - Perfmon - ServerAgent