[LeetCode] Excel Sheet Column Title

168. Excel Sheet Column Title

Given an integer columnNumber, return its corresponding column title as it appears in an Excel sheet.

For example:

plaintext
1
2
3
4
5
6
7
8
A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28
...
c++
1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution {
public:
string convertToTitle(int columnNumber) {
string res = "";
while(columnNumber) {
columnNumber -= 1;
res.push_back((columnNumber % 26) + 'A');
columnNumber /= 26;
}
reverse(begin(res),end(res));
return res;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2023/08/22/PS/LeetCode/excel-sheet-column-title/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.

Gitalking ...