[Leetcode] Excel Sheet column title find Excel table columns name

Source: Internet
Author: User

Given a positive integer, return its corresponding column title as appear in an Excel sheet.

For example:

    1, A    2, B    3, C    ...    AA, Z        

Credits:
Special thanks to @ifanchu for adding this problem and creating all test cases.

This problem and Excel Sheet column number is the Excel table ordinal is together, but I spend more time on this topic than above, the starting principle is the same, is a request, the problem from the low to high, each into a, then the original number is reduced by 26 times times, After 26, subtract the remainder, then reduce it by 26 times times, and so on, you can find the letters in each position. Finally, just flip the whole string over a bit. The code is as follows:

classSolution { Public:    stringConverttotitle (intN) {stringres ="";  while(n) {if(n% -==0) {res+='Z'; N-= -; }            Else{res+ = n% --1+'A'; N-= n% -; } N/= -;        } reverse (Res.begin (), Res.end ()); returnRes; }};

[Leetcode] Excel Sheet column title find Excel table columns name

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.