Skip to content

Latest commit

 

History

History
 
 

ExcelSheetColumnTitle

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Excel Sheet Column Title

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

Solution

进制转化,其实质就是把数字转成26进制

由于1->A, 2->B, 26->Z,即所以需要把n-1在操作

Code

string convertToTitle(int n) {
	string result;
	while (n) {
		result.push_back(--n % 26 + 'A');
		n /= 26;
	}
	return string(result.rbegin(), result.rend());
}

扩展

逆过程Excel Sheet Column Number