[Leetcode]62. Excel Sheet column Title Excel columns ordinal

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.

Subscribe to see which companies asked this question

Solution: And Excel Sheet Column number Instead, this time is 10 binary to 26 binary. From the low to high, each into a, then the original number is reduced by 26 times times, and then 26, then subtract the remainder, then reduce 26 times times, and so on, you can find the letters in each position. Finally, just flip the whole string over a bit.

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

[Leetcode]62. Excel Sheet column Title Excel columns ordinal

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.