当前位置: 首页 > news >正文

LeetCode171. Excel Sheet Column Number

文章目录

    • 一、题目
    • 二、题解

一、题目

Given a string columnTitle that represents the column title as appears in an Excel sheet, return its corresponding column number.

For example:

A -> 1
B -> 2
C -> 3

Z -> 26
AA -> 27
AB -> 28

Example 1:

Input: columnTitle = “A”
Output: 1
Example 2:

Input: columnTitle = “AB”
Output: 28
Example 3:

Input: columnTitle = “ZY”
Output: 701

Constraints:

1 <= columnTitle.length <= 7
columnTitle consists only of uppercase English letters.
columnTitle is in the range [“A”, “FXSHRXW”].

二、题解

class Solution {
public:int titleToNumber(string columnTitle) {int n = columnTitle.size();int res = 0;long long mul = 1;for(int i = n - 1;i >= 0;i--){int k = columnTitle[i] - 'A' + 1;res += k * mul;mul *= 26;}return res;}
};
http://www.lryc.cn/news/301409.html

相关文章:

  • pycharm创建py文件,自动带# -*- coding:utf-8 -*-
  • 希捷与索尼集团合作生产HAMR写头激光二极管
  • 电脑竖屏显示了怎么回复原状
  • Elasticsearch从入门到精通
  • Halcon 相机标定
  • 【JavaScript】深浅拷贝
  • CH32V3xx RT-Thread RS485实现modbus rtu master
  • 当网站遭到DDOS攻击怎么办?
  • ES6中的数组解构赋值【详解】
  • error An unexpected error occurred: “https://registry.npm.taobao.org
  • react中commit工作流程
  • C++类和对象-多态->多态的基本语法、多态的原理剖析、纯虚函数和抽象类、虚析构和纯虚析构
  • QShortcut
  • 浅谈语义分割、图像分类与目标检测中的TP、TN、FP、FN
  • Python基础教程:解构
  • Java 学习和实践笔记(12)
  • 学习数据结构和算法的第9天
  • 大龙谈智能内容 - 开工大吉
  • 中科大计网学习记录笔记(十二):TCP 套接字编程
  • 落实三大阶段目标,TRON全方位打通与BTC生态互联
  • MCU中断控制
  • C语言中的可变参数
  • Leetcode-103. 二叉树的锯齿形层序遍历
  • vs code“无法与远程服务器建立连接:XHR failed.”解决办法
  • 第五节 zookeeper集群与分布式锁_2
  • Shell脚本——提取目录名和文件名
  • wps使用方法(包括:插入倒三角符号,字母上面加横线,将word中的所有英文设置为time new roman)
  • 备战蓝桥杯---图论之最小生成树
  • 爬虫-华为云空间备忘录导出到docx-selenium控制浏览器行为-python数据处理
  • 网络安全的新防线:主动进攻,预防为先