> For the complete documentation index, see [llms.txt](https://senliuy.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://senliuy.gitbook.io/leetcode/di-liu-zhang-ff1a-shu-xue/q168-excel-sheet-column-title.md).

# Q168. Excel Sheet Column Title

直达：<https://leetcode.com/problems/excel-sheet-column-title/description/>

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

For example:

```
    1 -> A
    2 -> B
    3 -> C
    ...
    26 -> Z
    27 -> AA
    28 -> AB
```

## 分析

这道题是十进制转26进制，但是注意十进制是从1开始计数，所以开始的时候n要减1。

例如26 -> Z， (26-1)%26 = 25, 25+'A'对应的是Z。

## C++代码

```cpp
class Solution {
public:
    string convertToTitle(int n) {
        string res;
        char temp;
        while(n){
            n -= 1;
            int bit = n%26;
            temp = bit + 'A';
            res = temp + res;
            n /= 26;
        }
        return res;
    }
};
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://senliuy.gitbook.io/leetcode/di-liu-zhang-ff1a-shu-xue/q168-excel-sheet-column-title.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
