首页 > 其他 > 详细

171. Excel Sheet Column Number

时间:2020-03-31 01:37:29      阅读:110      评论:0      收藏:0      [点我收藏+]

Problem:

Given a column title as appear 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: "A"
Output: 1

Example 2:

Input: "AB"
Output: 28

Example 3:

Input: "ZY"
Output: 701

思路

Solution (C++):

int titleToNumber(string s) {
    int sum = 0, n = s.length();
    for (int i = 0; i < n; ++i)
        sum += (int(s[i]) - 64) * pow(26, n-1-i);
    return sum;
}   

性能

Runtime: 4 ms??Memory Usage: 6.1 MB

思路

Solution (C++):


性能

Runtime: ms??Memory Usage: MB

171. Excel Sheet Column Number

原文:https://www.cnblogs.com/dysjtu1995/p/12602099.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!