class Solution {
public:
stack<char> s;
char str[100];
string convertToTitle(int n) {
while(n > 0){
int last = n % 26;
s.push(last);
n = last==0? n/26-1 : n/26;
}
int index = 0;
while(!s.empty()){
int c = s.top();
if(0 == c)
str[index++] = 'Z';
else
str[index++] = (char)(c+64);
s.pop();
}
str[index] = '\0';
return string(str);
}
};
168. Excel Sheet Column Title
最新推荐文章于 2024-03-05 12:33:08 发布