Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
README.md
solve.cpp

README.md

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

You can’t perform that action at this time.