Leedcode OJ] #171 Excel Sheet Column number

Source: Internet
Author: User

"Disclaimer: All rights reserved, please indicate the source of the reprint, do not use for commercial purposes. Contact mailbox: [Email protected] "

title Link: https://leetcode.com/problems/excel-sheet-column-number/
Test Instructions:given a~z, which represent 1~26,aa-27,ab-28, and so on, now given a string of letters, requiring it to be converted to a number
Ideas:using the idea of the system, it can be converted into the idea of seeking the system.
Class Solution{public:    int Titletonumber (string s)    {        int ans = 0;        int len = S.length (), i,j;        for (i = 0; i<len; i++)        {            int cnt = len-1-i;            int a = s[i]-' a ' +1,q = 1;            while (cnt--)                q*=26;            ans=ans+a*q;        }        return ans;    };


Copyright NOTICE: This article is the original blogger article, if reproduced, please indicate the source

Leedcode OJ] #171 Excel Sheet Column number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.